官术网_书友最值得收藏!

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.
  • 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!

主站蜘蛛池模板: 江都市| 涟源市| 云龙县| 上杭县| 哈尔滨市| 依安县| 砀山县| 深州市| 荃湾区| 江永县| 许昌市| 长宁区| 沧州市| 金阳县| 右玉县| 开化县| 庐江县| 电白县| 萨迦县| 秦皇岛市| 兖州市| 循化| 慈利县| 集安市| 乌恰县| 黄梅县| 泰来县| 镇原县| 泾源县| 青州市| 玉山县| 曲松县| 宁陵县| 岑巩县| 昌宁县| 海宁市| 乌鲁木齐县| 敦煌市| 永康市| 广汉市| 黎平县|