zoukankan      html  css  js  c++  java
  • home应用的创建

    home应用的创建

    注册drf、弃用jdango的csrf

    # dev.py
    INSTALLED_APPS = [
        # ...
        'rest_framework',
    ]
    
    MIDDLEWARE = [
        'django.middleware.security.SecurityMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        # 'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
        'corsheaders.middleware.CorsMiddleware',
    ]
    

    创建 home 应用

    """
    1.前往apps目录下创建app:cd luffyapi/apps
    2.创建app:python ../../manage.py startapp home
    """
    

    配置 apps 到环境变量并注册home应用

    # dev.py
    import os
    import sys
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    sys.path.append(os.path.join(BASE_DIR, 'apps'))
    
    # 注:不添加环境变量,注册 应用 很麻烦,会出现 应用 找不到
    
    INSTALLED_APPS = [
        # ...
        'home'
    ]
    

    注册子路由

    # 主路由:urls.py
    from django.urls import include
    urlpatterns = [
    	# ...
        path('home/', include('home.urls')),
    ]
    
    # 子路由:home/urls.py
    from django.urls import path, re_path
    
    urlpatterns = [
        
    ]
    
  • 相关阅读:
    Consul 原理
    google ads api —— budget
    rabbitmq 启动报错 Kernel pid terminated
    maven 打依赖包命令
    【原创】Linux基础之supervisor
    Git 常用命令
    Thinkpad T14 AMD版无线网卡不可用
    在Windows10中安装解压版MySQL 8.X
    Git 分支管理参考模型
    Feign入门介绍
  • 原文地址:https://www.cnblogs.com/king-home/p/11197565.html
Copyright © 2011-2022 走看看