zoukankan      html  css  js  c++  java
  • Django 安装 创建项目 运行项目

    Django基础

    框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统,简单地说,就是你用别人搭建好的舞台来做表演。

    对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端。

    WSGI:Web Server Gateway Interface

    Django准备

    下载
    ------------------------------------------------
    cmd --> pip install django==1.11.18
    #下面是一个国内资源链接,解决网络差问题不好下载
     pip install django==1.11.18 -i https://pypi.douban.com/simple/
    pycharm 下载 国外源
    加自己源
     settings ->project ->project interpreter ->双击django->左侧点Manage Repositories进入后点击右侧加号->添加进去http链接
    specify version 选择版本
    ------------------------------------------------
    安装成功的查看
    cmd --> pip list
    ------------------------------------------------
    pycharm --> settings ->project ->project interpreter ->  减号删除
    pip uninstall django 这是cmd下的卸载Django
    -------------------------------------------------
    **创建项目**
    cmd下 :
    根目录右键+shift 打开命令行
    磁盘-->python-->Script-->django-admin.exe
    django-admin startproject 项目名   #创建好了
    pycharm下创建 :
    任意目录下 --> file-->new project -->django-->location 路径+项目名称-->create-->open new window -->上面三角运行整个项目
    ****************************************************
    --------下面cmd启动项目-----------
    ------manage.py 执行命令---------
    python manage.py runserver         # 127.0.0.1:8000
    python manage.py runserver  80    # 127.0.0.1:80  改端口
    python manage.py runserver  0.0.0.0:80    # 0.0.0.0:80  改ip

    配置相关

    settings 打开 -->allowed_hosts = ['*']   --项目部署  Linux机器--
    
    import OS
    根目录 -->项目目录 -->settings.py打开
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    debug = True      --当前处于开发状态--
    大黄页 提示  错误在哪   allowed_hosts = ['*'] 
    --------------------------------------------------------------------
    debug = False     --- 上线前必须改 ---   allowed_hosts = ['*'] 
    --------------------------------------------------------------------
    Templates (模板)= [列表 'DIRS': [os.path.join(BASE_DIR,'templates')],]
    模板html文件放在templates下
    --------------------------------------------------------------------
    DATABASES  数据库
    --------------------------------------------------------------------
    STATIC_URL = '/static/'  # 别名    
    不经常做修改的文件 静态文件 

    应用Django 框架

    urls.py  --路由  写的是url地址和函数的对应关系
    
    from django.conf.urls import url
    from django.contrib import admin
    from django.shortcuts import HttpResponse
    def index(request):
        return HttpResponse('这是index页面')
    
    urlpatterns = [
        url(r'^admin/', admin.site.urls),
        url(r'^index/', index),
    ]
  • 相关阅读:
    LeetCode Count of Range Sum
    LeetCode 158. Read N Characters Given Read4 II
    LeetCode 157. Read N Characters Given Read4
    LeetCode 317. Shortest Distance from All Buildings
    LeetCode Smallest Rectangle Enclosing Black Pixels
    LeetCode 315. Count of Smaller Numbers After Self
    LeetCode 332. Reconstruct Itinerary
    LeetCode 310. Minimum Height Trees
    LeetCode 163. Missing Ranges
    LeetCode Verify Preorder Serialization of a Binary Tree
  • 原文地址:https://www.cnblogs.com/zhangchen-sx/p/10269773.html
Copyright © 2011-2022 走看看