码迷,mamicode.com
首页 > 其他好文 > 详细

django 初试

时间:2016-08-06 14:21:04      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

/**************************************************************************************
 *                               django 初试
 * 说明:
 *     昨天打搭了dgango的服务器,今天学一下怎么来输出一个hello world出来。
 *                 
 *                                                  2016-8-6 深圳 南山平山村 曾剑锋
 *************************************************************************************/

一、创建blog应用:
    django-admin startapp blog

二、目录结构:
    aplex@aplex:~/website/mysite$ ls
    blog  manage.py  mysite
    aplex@aplex:~/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
    aplex@aplex:~/website/mysite$ 

三、settings配置:
    aplex@aplex:~/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配置:
    aplex@aplex:~/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:
    aplex@aplex:~/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>)
    aplex@aplex:~/website/mysite$ 

六、效果:

 技术分享

django 初试

标签:

原文地址:http://www.cnblogs.com/zengjfgit/p/5743896.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!