django+vue

  1. diango 只能加载静态js,和flask一样

  2. 关于如何利用vue创建web,请查看flask + vue-CSDN博客

  3. 安装django

pip install django

  1. 创建新项目

django-admin startproject myproject

5.django 中可以包含多个app

5.1 创建一个app

cd myproject

python manage.py startapp myapp

5.2 在目录myapp下,创建目录templates

6.添加myapp到django中,修改settings.py

INSTALLED_APPS = [

...

'myapp',

...

]

7.在 myapp/urls.py中,添加如下内容

from . import views

urlpatterns = [

path('', views.index, name='index'),

]

8.在myapp/views.py中添加如下内容

def index(request):

return render(request, 'index.html')

  1. 在myproject/urls.py中,添加如下内容

from django.urls import include, path

urlpatterns = [

path('admin/', admin.site.urls),

path('', include('myapp.urls')),

]

  1. 在myproject目录下创建static目录

myproject/static

Note:static目录跟myap和子myproject目录同级

  1. 复制web/dist/js web/dist/css 目录到myproject/static中

  2. 复制web/dist/index.html web/dist/favicon.ico 到myapp/templates中

  3. 修改myapp/templates/index.html中的src的路径,在下边的路径前加'/static'

/js/chunk-vendors.b956e054.js

/js/app.34b81487.js

/css/app.2cf79ad6.css

修改后的值为

/static/js/chunk-vendors.b956e054.js

/static/js/app.34b81487.js

/static/css/app.2cf79ad6.css

  1. 执行django

python manage.py runserver

相关推荐
默_笙4 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
qq_426003964 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
A黄俊辉A4 天前
uniapp webview中实现 app和内嵌的H5双向通信
vue.js·json
虎头金猫4 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
长沙三为智能科技4 天前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
伞伞悦读4 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
只睡四小时4 天前
Canvas 弹道联机实战:700 行 + 固定时间步长
python·websocket·html5·游戏开发·canvas
奇思妙想聪明勤奋的小羊4 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
honkun64 天前
vue 表格组件 vxe-table 配置 ajax 请求自动加载数据与表单查询
vue.js·vxe-table
lpfasd1234 天前
2026年第38周GitHub趋势周报
python·科技·github