您的位置:首页 > 编程语言 > Python开发

使用Django搭建一个简单的Python Web工程

2014-11-12 16:19 731 查看
配置好python及django之后就可以使用框架搭建一个简单的web project



执行这个命令之后,就会在PythonWebProject的文件目录下生成一个名字为myFirstPyWebProject的文件夹。这里边包含了web工程的文件目录:





之后启动这个web项目:



这时候在浏览器中输入:
http://localhost:8000/
浏览器中可以看到返回的界面:

It worked!

Congratulations on your first Django-powered page.

Of course, you haven't actually done any work yet. Next, start your first app by running
python manage.py startapp [app_label]
.

You're seeing this message because you have
DEBUG = True
in your Django settings file and you haven't configured any URLs. Get to work!

然后我们在urls.py的相同目录中增加view.py文件:

from django.http import HttpResponse

def hello(request):
return HttpResponse("hello, Django!")
并且修改urls.py:
from django.conf.urls import include, url
from django.contrib import admin
from myFirstPyWebProject.view import hello

urlpatterns = [
# Examples:
# url(r'^$', 'myFirstPyWebProject.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),

url(r'^admin/', include(admin.site.urls)),
url(r'^hello/$', hello),
]


这时候访问: http://localhost:8000/hello/
就可以看到返回的hello, Django!

这样一个简单的web工程就搭建好了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python web Django