Django安装与创建项目

时间:2021-04-27 14:38:23

下载

https://media.djangoproject.com/releases/1.11/Django-1.11.20.tar.gz

解压

tar -zvxf Django-1.11.20.tar.gz -C /home/pythonSpace/

安装

sudo python setup.py install

查看是否安装

>>> import django
>>> django.VERSION
(1, 11, 20, u'final', 0)
>>> django.get_version()
'1.11.20'

创建一个项目dog,项目下包含app

django-admin startproject dog

创建一个app,进入project目录下操作

python manage.py startapp learn

将index加入到setting.py中

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles', 'learn',
]

修改views.py中的内容为

# -*- coding: utf-8 -*-
from django.http import HttpResponse def index(request):
return HttpResponse(u"Hello Eden!")

修改urls.py

from django.conf.urls import url
from django.contrib import admin
from learn import views as learn_views # new urlpatterns = [
url(r'^$', learn_views.index), # new
url(r'^admin/', admin.site.urls),
]

运行

python manage.py runserver 9000