Home  >  Article  >  Backend Development  >  Summary of commands commonly used in Django development

Summary of commands commonly used in Django development

高洛峰
高洛峰Original
2016-10-17 14:35:561149browse

1. Create a Django Project

#使用下面的命令可以创建一个project
django-admin.py startproject mysite
   
#创建好之后可以看到如下的project结构
mysite/
  manage.py
  mysite/
      __init__.py
      settings.py
      urls.py
      wsgi.py

2. Start the newly created Project

Enter the mysite directory and run the python manage.py runserver command. By default, the startup port of runserver is 8000. If you need to change the port number, you can pass it in as a parameter

python manage.py runserver 8080

3. Start the interactive command mode

Usually you need to test some simple Django code , then you can use this interactive shell to complete

python manage.py shell

4. Create Django App

python manage.py startapp books

# 创建好的App目录结构如下
books/
  __init__.py
  models.py
  tests.py
  views.py

5. Verify the validity of the Model

Usually to connect to the database , we need to create a Model corresponding to the database table. After the Model is created, you can use the following command to verify the validity of the Model

python manage.py validate

If you see the following output information, it means there is no problem with your Model

0 errors found

6. Generate SQL schema

When confirming that there is no problem with the Model, Django provides us with a tool to help generate the schema for creating the database

python manage.py sqlall books

This command can output the schema for creating the Table to Command line, but it cannot be created synchronously to the database. In order to synchronize it to the database, Django has also considered it for us

7. Synchronize Model to the database

python manage.py syncdb
# Django 还提供了另一个工具方便我们直接登录到数据库中
python manage.py dbshell



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn