1.django源码安装
进入源码目录,执行python setup.py install
2.创建django工程
进入工程父目录,执行django-admin startproject test1
3.创建django应用
进入工程目录test1,执行django-admin startapp app1
4.配置settings.py
INSTALLED_APP add----->app1
5.配置urls.py
url(r'app1/idnex/$', 'app1.views.index')
6.配置views.py
from django.shortcuts import render_to_response
def index(req):
return render_to_response('index.html')
或
from django.shortcuts import render from django.http import HttpResponse from django.template import loader, Context def index(req): t = loader.get_template('index.html') c = Context({}) return HttpResponse(t.render(c))
7.创建html文件
先在应用目录app1下创建templates目录,进入templates目录,创建index.html文件
<html> <head></head> <body> <h1>Hello test1!</h1> </body> </html>
8.启动服务
进入工程目录,python manager.py runserver
默认url: 127.0.0.1:8000
转载请注明原文地址: https://ju.6miu.com/read-25007.html