Django 前后端统一部署

Posted by JC on 2019-05-30 11:31:38 Updated on 2019-05-30 11:31:38

https://cloud.tencent.com/developer/article/1005607

前端代码 build 后放入 Django 项目下

urls.py 添加两行

from django.views.generic import TemplateView

urlpatterns = [
    path('dashboard/', TemplateView.as_view(template_name="index.html")),
]

TEMPLATES 添加 DIRS

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['dist'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

添加 STATICFILES_DIRS css/js 静态文件放进去

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "dist/static"),
]

python3 manange.py runserver 后就能访问了

tags: django


BMC logoBuy me a coffee via Alipay or Wechat Pay