Python Example-django common commands

Source: Internet
Author: User
Tags cos

1. Create a new Django project:

project-  nameorDjango Project-name

2. A sub-app under the new project log: (yes to the generated project folder)

app-  nameorDjango App-name

3. Synchronize the database:

python manage.py syncdb   1.7  . Versions 1 and above need to use the following command python manage.py makemigrationspython manage.py migrate

This method creates a table, and when you add a class to the models.py, you can run it to automatically create a table in the database without creating it manually.

Note: If you modify an existing models, Django before Django 1.7 cannot change the table structure automatically.

4. Start the project service:

# when the prompt port is occupied, other ports can be used:python manage.py runserver 8001#  listen to all available IPpython manage.py Runserver 0.0.0.0:8000#  If it is an external network or LAN computer can use other computers to view the development server #  access to the corresponding IP plus port, such as HTTP/ 172.16.20.2:8000

5. Clear the database:

Python manage.py Flush

6. Create a Super Administrator:

Python manage.py Createsuperuser

7. Import and Export data:

Python manage.py dumpdata appname > appname.jsonpython manage.py loaddata Appname.json

8.Django Project Terminal:

Python manage.py Shell

If you installed the Bpython or Ipython will automatically use their interface, recommend the use of Bpython

9. Database command line : ( inline SQLite)

Python manage.py Dbshell

10. More Commands:

python manage.py # you can see a detailed list that is especially useful when you forget your name. 

The above commands are used under this directory after the project is created.

eg

[email protected] desktop]$lsmysite Zqxt_tmpl zqxt_views#project directory, here are 3[email protected] desktop]$cd mysite[cos @localhost mysite]$Python manage.py#Django Commands.Type ' manage.py help <subcommand> ' forHelp on a specific subcommand.    Available Subcommands:[auth] ChangePassword Createsuperuser[django] Check compilemessages createcachetable Dbshell diffsettings dumpdata flush inspectdb loaddata makemessages makemigrations Migrate R    unfcgi Shell showmigrations SQL Sqlall sqlclear sqlcustom sqldropindexes sqlflush sqlindexes Sqlmigrate sqlsequencereset squashmigrations startapp startproject syncdb test testserver Validat E[sessions] clearsessions[staticfiles] collectstatic findstatic runserver[cos @localhost desktop]$

Python Example-django common 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.