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

相关推荐
金銀銅鐵22 分钟前
[Python] 用 turtle 来绘制瑞典国旗
python
Albert Edison23 分钟前
【GUI 自动化测试】Pywinauto 常见操作
自动化测试·python·pywinauto
海兰24 分钟前
【高速缓存】RedisVL为文本生成嵌入向量实践指南
人工智能·python·机器学习
2601_9557600732 分钟前
如何用 Claude Opus 5 API 批量扩展长尾关键词和文章选题
前端·python·搜索引擎
艾斯特_1 小时前
从模型调用到可用聊天应用:会话状态与消息协议
python·ai·aigc
Marst Code1 小时前
Python 3.9 已停止维护!从 3.9 到 3.14 全版本深度对比,生产环境该选哪个?
开发语言·python
llwszx1 小时前
【Java/Go后端手撸原生Agent(第九篇):Plan-and-Execute规划模式——从“走一步看一步“到“先谋后动“】
java·python·golang·agent开发·plan模式·规划执行模式
lxw18449125141 小时前
Python uv 完整使用教程
python·conda·pip·uv
hangyuekejiGEO2 小时前
临沂GEO技术解析与行业应用方案
人工智能·python
不做Java程序猿好多年3 小时前
Java中 String、StringBuffer、StringBuilder 的区别详解
开发语言·python