- Learning Website Development with Django
- Ayman Hourieh
- 229字
- 2021-07-02 11:41:17
Summary
In this chapter, we learned about the three main components of Django: the view, model and template. We wrote data models to store the data of our application, and then created views and templates to display this data. We also learned how to map URLs to views, and how to use the interactive console to experiment with our Django project.
Below is a summary of the Django features covered in this chapter:
- To create an application within a project, run the following command:
$ python manage.py startapp <app-name>
- After writing a data model, the following command should be run to create the corresponding tables in the database:
$ python manage.py syncdb
- To view the SQL queries generated by Django, issue the following command:
$ python manage.py sql <app-name>
- Data models provide a variety of methods to interact with the database engine:
- The
save
method saves an object into the database. - The
objects.get
method retrieves an object by a unique field. - The
objects.all
method retrieves a list of all objects. - The
delete
method deletes an object from the database.
- The
- To generate a 404 "Page Not Found" error, raise an exception of type type
Http404
.
In the next chapter, we will continue developing our application, but we will focus mostly on user management features, such as registration and logging in. The next chapter provides a lot of useful information, so read on!
推薦閱讀
- 做好PPT就靠這幾招:圖解力+吸引力+說(shuō)服力
- Moodle 1.9 for Teaching 7/14 Year Olds: Beginner's Guide
- Getting Started with Microsoft Application Virtualization 4.6
- 中文版CorelDRAW X7基礎(chǔ)培訓(xùn)教程(移動(dòng)學(xué)習(xí)版)
- 中文版Photoshop CS6平面設(shè)計(jì)實(shí)例教程(第2版)
- Cinema 4D完全實(shí)戰(zhàn)技術(shù)手冊(cè)
- SolidWorks 2018有限元:運(yùn)動(dòng)仿真與流場(chǎng)分析自學(xué)手冊(cè)
- Solid Edge 機(jī)械設(shè)計(jì)基礎(chǔ)及應(yīng)用
- Photoshop+CorelDRAW 字體設(shè)計(jì)與創(chuàng)意:草圖/實(shí)現(xiàn)/包裝(微課版)
- Mastering Zabbix
- 中文版3ds Max 2022基礎(chǔ)教程
- 企業(yè)虛擬化實(shí)戰(zhàn):VMware篇
- Oracle E/Business Suite R12 Supply Chain Management
- 圖像顯著區(qū)域提取方法及其應(yīng)用研究
- AutoCAD 2018中文版完全自學(xué)手冊(cè)