标签:ant ber dex gravity uil stat set var project
1、下载django ,下载地址:https://www.djangoproject.com/download
2、解压Django-1.xx.yy.tar.gz ,进入解压目录执行命令
sudo python setup.py install
3、查看是否安装成功
django-admin.py --version
4、创建一个工程
django-admin.py startproject HelloWorld
5、运行django
$cd HelloWorld # 切换到我们创建的项目
$ python manage.py runserver #启动服务器
6、创建一个应用
$ cd HelloWorld # 切换到我们创建的项目
$ django-admin.py startapp hello
7、修改工程中settings.py 中的INSTALLED_APPS
INSTALLED_APPS = [
‘django.contrib.admin‘,
‘django.contrib.auth‘,
‘django.contrib.contenttypes‘,
‘django.contrib.sessions‘,
‘django.contrib.messages‘,
‘django.contrib.staticfiles‘,
‘hello‘
]
8、在hello中创建一个templates用于存放模版文件
9、中hello中views.py中写入相应代码
# coding:utf-8
from django.http import HttpResponse
from django.template import loader,Context
def index(request):
t = loader.get_template("index.html")
c = Context({"title": "djangon"})
return HttpResponse(t.render(c))
10、配置工程HelloWorld,修改urls.py如下:
from django.conf.urls import url
from django.contrib import admin
from hello import views as learn_views
urlpatterns = [
url(r‘^$‘, learn_views.index), # new
url(r‘^admin/‘, admin.site.urls),
]
11、运行项目:
$ python manage.py runserver
12、在浏览器中查看
http://127.0.0.1:8000/
标签:ant ber dex gravity uil stat set var project
原文地址:http://www.cnblogs.com/zxyGo/p/6545500.html