zoukankan      html  css  js  c++  java
  • django 01--创建APP

    初体验

    安装

    pip install django
    

    建立工程

    django-admin startproject mysite
    

    运行工程

    python manage.py runserver
    python manage.py runserver 8000
    python manage.py runserver 0.0.0.0:8000
    

    第一个页面

    在mysite/mysite下创建views.py

    # -*- coding: utf-8 -*-
    from django.http import HttpResponse
    
    def index(request):
        return HttpResponse("<h2>你好,Django!</h2>")
    

    将urls.py修改为

    from django.conf.urls import url
    from django.contrib import admin
    from . import views
    
    urlpatterns = [
        url(r'^admin/', admin.site.urls),
    
        url(r'^$', views.index, name='index'),
    ]
    

    访问

    访问127.0.0.1:8000

    增加APP

    python manage.py startapp west
    

    在mysite/setting.py中添加:

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
    
        'west',
    ]
    

    将mysite/urls.py改成:

    from django.conf.urls import include, url
    from django.contrib import admin
    from . import views
    
    urlpatterns = [
        url(r'^admin/', admin.site.urls),
    
        url(r'^$', views.index, name='index'),
        url(r'^west/', include('west.urls')),
    ]
    

    增加文件west/urls.py

    from django.conf.urls import url
    from . import views
    
    urlpatterns = [
        url(r'^$', views.index),
    ]
    

    增加文件west/views.py

    # -*- coding: utf-8 -*-
    from django.http import HttpResponse
    
    
    def index(request):
        return HttpResponse("<h2>西餐!</h2>")
    

    访问http://127.0.0.1:8000/west,查看效果。

  • 相关阅读:
    专注技术热爱生活
    js效果我的蒙板效果实现
    KMP算法
    九月份发现的好东东记录
    ATL SERVER
    不要把项目开发当做自己个人的展示舞台
    看ProMesh.NET项目领悟到的
    谈谈编译原理和其在WEB开发中的应用3
    开发更深层次的交流产品
    Hibernate3.3.2 手动配置annotation环境
  • 原文地址:https://www.cnblogs.com/keer2345/p/6015958.html
Copyright © 2011-2022 走看看