1. Download Django: Https://www.djangoproject.com/download
2, decompression django-1.xx.yy.tar.gz, into the Extract directory execution command
sudo python setup.py install
3. See if the installation is successful
django-admin.py --version
4. Create a project
django-admin.py startproject HelloWorld
5. Run Django
- 1
$cd HelloWorld # 切换到我们创建的项目
- 2
$ python manage.py runserver #启动服务器
6. Create an application
$ cd HelloWorld # 切换到我们创建的项目$ django-admin.py startapp hello
7. Revise the Installed_apps of settings.py in the project
INSTALLED_APPS = [ ‘django.contrib.admin‘, ‘django.contrib.auth‘, ‘django.contrib.contenttypes‘, ‘django.contrib.sessions‘, ‘django.contrib.messages‘, ‘django.contrib.staticfiles‘, ‘hello‘]
8. Create a templates in Hello to store the template file
9. Write the corresponding code in views.py in Hello
# coding:utf-8from django.http import HttpResponsefrom django.template import loader,Contextdef index(request): t = loader.get_template("index.html") c = Context({"title": "djangon"}) return HttpResponse(t.render(c))
10, Configuration engineering HelloWorld, modify urls.py as follows:
from django.conf.urls import urlfrom django.contrib import adminfrom hello import views as learn_viewsurlpatterns = [ url(r‘^$‘, learn_views.index), # new url(r‘^admin/‘, admin.site.urls),]
11, the operation of the project:
$ python manage.py runserver
12. viewing in the browser
http://127.0.0.1:8000/
Django installation configuration (for MAC)