首页 > 编程语言 > 详细

python 点滴记录13:django 初尝试

时间:2015-07-02 17:42:53      阅读:160      评论:0      收藏:0      [点我收藏+]

use django to create website:


1、create new django project

#django-admin.py startproject test1
test1/
├── manage.py
└── test1
    ├── __init__.py
    ├── settings.py
    ├── urls.py
    └── wsgi.py


2、create new django application,in the new project directory:

#python manage.py startapp web
test1/
├── manage.py
├── test1
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   └── wsgi.py
└── web
    ├── admin.py
    ├── __init__.py
    ├── migrations
    │   └── __init__.py
    ├── models.py
    ├── tests.py
    └── views.py


3、add the new application to project‘s settings.py in INSTALLED_APPS:

INSTALLED_APPS = (
    ‘django.contrib.admin‘,
    ‘django.contrib.auth‘,
    ‘django.contrib.contenttypes‘,
    ‘django.contrib.sessions‘,
    ‘django.contrib.messages‘,
    ‘django.contrib.staticfiles‘,
    ‘test1‘,
)

4、create view in the application‘s views.py:

from django.http import HttpResponse
def index(request):
        return HttpResponse("hello django!")


5、in project‘s urls.py,add mapping to the application:

from test1.views import index
urlpatterns = patterns(‘‘,
    url(r‘^test1/‘, ‘test1.views.index‘),
)


6、url:http://ip:8000/test1 


python 点滴记录13:django 初尝试

原文:http://ahaii.blog.51cto.com/1695127/1670209

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!