zoukankan      html  css  js  c++  java
  • django 初试

    /**************************************************************************************
     *                               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$ 
    
    六、效果:

     

  • 相关阅读:
    3.2.1 正則表達式的语法(1)
    朴素贝叶斯(naive bayes)
    有方向的运动js
    碰撞检測之OBB-OBB的SweepTest
    左右上下都能滚动的效果
    C语言中 fputs() fgets() 的使用方法
    Apache Module mod_ssl
    "ssllabs" website and "testssl" website
    Google发布SSLv3漏洞简要分析报告
    为什么要使用TLSv1.2和System SSL?
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/5743896.html
Copyright © 2011-2022 走看看