新学习Django,还不熟练。根据官方文档,总结下常用的操作。
包括:创建project、启动project、创建app
Creating a project
From the command line, cd
into a directory where you’d like to store your code, then run the following command:
$ django-admin startproject mysit
This will create a mysite
directory in your current directory. If it didn’t work, see Problems running django-admin.
Let’s look at what startproject
created:
mysite/
manage.py
mysite/ __init__.py settings.py urls.py wsgi.py
The development server
Let’s verify your Django project works. Change into the outer mysite
directory, if you haven’t already, and run the following commands:
$ python manage.py runserver
You’ll see the following output on the command line:
Performing system checks... System check identified no issues (0 silenced). You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them. April 13, 2018 - 15:50:53 Django version 2.0, using settings 'mysite.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
Creating the Polls app
To create your app, make sure you’re in the same directory as manage.py
and type this command:
$ python manage.py startapp polls
That’ll create a directory polls
, which is laid out like this:
polls/
__init__.py
admin.py apps.py migrations/ __init__.py models.py tests.py views.py