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