/************************************************************************************** * django 初试 * 说明: * 昨天打搭了dgango的服务器,今天学一下怎么来输出一个hello world出来。 * * 2016-8-6 深圳 南山平山村 曾剑锋 *************************************************************************************/ 一、创建blog应用: django-admin startapp blog 二、目录结构: [email protected]:~/website/mysite$ ls blog manage.py mysite [email protected]:~/website/mysite$ tree . ├── blog │ ├── admin.py │ ├── admin.pyc │ ├── __init__.py │ ├── __init__.pyc │ ├── models.py │ ├── models.pyc │ ├── tests.py │ ├── views.py │ └── views.pyc ├── manage.py └── mysite ├── __init__.py ├── __init__.pyc ├── settings.py ├── settings.pyc ├── urls.py ├── urls.pyc └── wsgi.py 2 directories, 17 files [email protected]:~/website/mysite$ 三、settings配置: [email protected]:~/website/mysite$ cat mysite/settings.py ...... INSTALLED_APPS = ( ‘django.contrib.admin‘, ‘django.contrib.auth‘, ‘django.contrib.contenttypes‘, ‘django.contrib.sessions‘, ‘django.contrib.messages‘, ‘django.contrib.staticfiles‘, ‘blog‘, ) ...... 四、urls配置: [email protected]:~/website/mysite$ cat mysite/urls.py from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns(‘‘, # Examples: # url(r‘^$‘, ‘mysite.views.home‘, name=‘home‘), # url(r‘^blog/‘, include(‘blog.urls‘)), url(r‘^admin/‘, include(admin.site.urls)), url(r‘^blog/index/$‘, ‘blog.views.index‘), ) 五、view: [email protected]:~/website/mysite$ cat blog/views.py from django.shortcuts import render from django.http import HttpResponse # Create your views here. def index(req): return HttpResponse(‘<h1>hello world</h1>‘) [email protected]:~/website/mysite$ 六、效果:
时间: 2024-11-22 21:14:43