Django basic Commands

Source: Internet
Author: User

This section is intended to help you understand some Django The most basic commands, please try to remember them, and practice a lot of

1. Create a new Django Project

1

Django-admin.py?startproject?project-name

a Project as a project, Project-name project name, change to your own, to meet Python the variable naming convention (the beginning of an underscore or letter)

2. Create a new app

1

2

Python?manage.py?startapp?app-name

or? django-admin.py?startapp?app-name

typically a project has multiple app, Of course, universal. app It can also be used in multiple projects.

3. Synchronizing the database

1

2

3

4

5

python?manage.py?syncdb

??

note: django?1.7.1 and above require the following command

python?manage.py?makemigrations

python?manage.py?migrate

This method can create a table, When you add a class in models.py

Note: For an existing models Modified, django 1.7 previous version of django South, See django database migration

4. using the development server

Development server, that is, the development of the use of general code changes will be automatically restarted, convenient debugging and development, but due to performance issues, it is recommended only for testing, do not use in the production environment.

1

2

3

4

5

6

7

8

9

10

11

python?manage.py?runserver

??

#? When the prompt port is occupied, you can use a different port:

python?manage.py?runserver?8001

python?manage.py?runserver?9999

(can also kill a process that consumes ports)

??

#? Monitor all available? IP? (the computer may have one or more intranet IPs, one or more extranet IPs, which have multiple IP addresses)

python?manage.py?runserver? 0.0.0.0:8000

#? If it is an extranet or LAN computer can use other computers to view the development server

#? Access corresponding? IP plus port, e.g. http://172.16.20.2:8000

5. Clear the database

1

Python?manage.py?flush

This command will ask if it is Yes or is No, Select Yes will erase all the data, leaving only empty tables.

6. Create a Super Administrator

1

2

3

4

5

6

python?manage.py?createsuperuser

??

#? Follow the prompts to enter the user name and the corresponding password is OK The mailbox can be left blank, the user name and password are required

??

#? User password can be used:

python?manage.py?changepassword?username

7. Export Data Import Data

1

2

Python?manage.py?dumpdata?appname?>?appname.json

Python?manage.py?loaddata?appname.json

For data operations See: Data import Data Migration , now that you know how to use it.

8. Django Project Environment Terminal

1

Python?manage.py?shell

If you have installed Bpython or Ipython will automatically use their interface, recommended installation Bpython .

This command and run directly Python or Bpython enter shell The difference is: You can in this shell Inside Call the current project's Span style= "Font-family:verdana" > models.py API for operational data, there are some small tests that are very handy.

9. Database command line

1

Python?manage.py?dbshell

Django will automatically enter the settings.py set in the database, if it is MySQL or PostgreSQL, The database user password is required.

The database can be executed at this terminal. SQL statement. If you're familiar with SQL , you might like this way.

More Commands

1

python?manage.py on terminal? You can see the detailed list, which is especially useful when you forget the sub-name.

Django basic Commands

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.