Common django commands

Source: Internet
Author: User

Common django commands
Django basic commands

This section mainly aims to help you understand some of the most basic django commands,Please remember them and exercise more

1. Create a django project
django-admin.py startproject project-name

A project is a project, and the project-name project name is changed to your own. It must comply with the Python variable naming rules (starting with an underscore or letter)

2. Create an app
python manage.py startapp app-nameOr django-admin.py startapp app-name

Generally, a project has multiple apps. Of course, generic apps can also be used in multiple projects.

3. Synchronize Databases
python manage.py syncdb Note: The following commands are required for Django 1.7.1 and later versions:python manage.py makemigrationspython manage.py migrate

In this way, you can create a table. When you add a class in models. py, you can run it to automatically create a table in the database without manual creation.

Note: If you modify the existing models, Django versions earlier than Django 1.7 cannot automatically change the table structure. However, there is a third-party tool south. For details, see the Django database migration section.

4. Use the Development Server

The development server is used during development. Generally, the code is automatically restarted after modification to facilitate debugging and development. However, due to performance problems, it is recommended that the server be used only for testing and not for production environments.

python manage.py runserver # When prompted that the port is in use, you can use another port:python manage.py runserver 8001python manage.py runserver 9999(Yes, of course.killDrop the process that occupies the port) # Listen to all available ip addresses (the computer may have one or more Intranet ip addresses, one or more Internet ip addresses, that is, multiple ip addresses)python manage.py runserver 0.0.0.0:8000# If it is an internet or LAN computer, you can use another computer to view the Development Server# Access the corresponding ip address and port, such as http: // 172.16.20.2: 8000
5. Clear the database
python manage.py flush

This command will ask whether it is yes or no. If yes is selected, all data is cleared, leaving only empty tables.

6. Create a super Administrator
python manage.py createsuperuser # Enter the user name and password as prompted. Leave the mailbox blank. the user name and password are required. # Change the user password:python manage.py changepassword username
7. export data to import data
python manage.py dumpdata appname > appname.jsonpython manage.py loaddata appname.json

For details about data operations, see import data migration. Now you can understand this usage.

8. Django project environment Terminal
python manage.py shell

If you have installed bpython or ipython, the interface will be automatically used. We recommend that you install bpython.

The difference between this command and directly running python or bpython to enter the shell is that you can call the models of the current project in this shell. the APIs in py are very convenient for some small tests on operation data.

9. Database Command Line
python manage.py dbshell

Django will automatically enter the database set in settings. py. If it is MySQL or postgreSQL, it will require you to enter the database user password.

On this terminal, you can execute the SQL statement of the database. If you are familiar with SQL, you may like this method.

10. More commands Enter python manage. py on the terminal to view the detailed list, which is especially useful when you forget the subname.

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.