首先安装pycheam,python,djingo。
在pychram中新建一个djingo项目
在web2目录下新建views.py文件,目录如下:
接下来在views.py文件中编写helloworld代码:
1
2
3
4
5
|
# -*- coding: utf-8 -*
from
django.http
import
HttpResponse
def
hello(request):
return
HttpResponse(
"Hello world! This is my first trial. [笔记]"
)
|
还需要配置urls.py文件完成映射
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
from
django.conf.urls
import
patterns, include, url
from
web2.views
import
hello
from
django.contrib
import
admin
from
django.conf.urls
import
*
admin.autodiscover()
urlpatterns
=
patterns('',
# Examples:
# url(r'^$', 'web2.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r
'^admin/'
, include(admin.site.urls)),
(
'^hello/$'
, hello),
)
|
一定要先导入hello
from web2.views import hello
然后启动项目,在浏览器打开
本文转自 matengbing 51CTO博客,原文链接:http://blog.51cto.com/matengbing/1904768