Django commands are based on the Django book

Source: Internet
Author: User

  1. Django-Admin startproject mysite create a Django
  2. Python manage. py runserver running server.
  3. PythonManage. pyShell runs similar to ipython. Some configurations in this way can take effect.
  4. Before connecting to the database, you must create a database. When creating a database, you must specify the character set and database permissions, and the user name and password. load the relevant information into the Django configuration file. the focus is on the configuration of the database itself (independent of Django). Django is opposite to Django configuration.
  5. Python manage. py validate verifies the validity of the model.
  6. Python manage. py Startapp books has a Convention on the app: if you use the Django database layer (model), You must create a Django app. The model must be stored in apps.
  7. Python manage. py sqlall books only prints SQL statement segments
  8. Python manage. py syncdb generation table.
  9. Call ''her her. Objects. All () ''' to obtain all objects of the ''her her'' class in the database.
  10. When you use the Django modle API to create an object, Django does not save the object to the database unless you call the ''save () ''method.
  11. One-step object creation and storage to the database, such as P1 = publisher. Objects. Create (name = 'apress ',......)
  12. ''Filter () ''method to filter data publisher. Objects. Filter (name = 'apache', state_province =" ca ")
  13. The Django. contrib. staticfiles in setting. py must be uncommented. Otherwise, CSS cannot be applied on the admin page, which is black and white.
  14. To create an admin. py under/bin/mysite/books/, the following content is not displayed on the admin page:
    From Django. contrib import admin from models import book, author, publisher Admin. Site. Register (book) Admin. Site. Register (publisher) Admin. Site. Register (author)
  15. Process primary keys and Foreign keys
    Authors = models. manytomanyfield (author)
    Publisher = models. foreignkey (publisher)
  16. Email = models. emailfield (Blank = true) Set this field to optional.
  17. If you want to allow a date type (Datefield,Timefield,Datetimefield) Or numeric type (Integerfield,Decimalfield,Floatfield) The field is empty. You need to useNull = true* And *Blank = true.Publication_date = models. datefield (blank = true, null = true)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.