当前位置:   article > 正文

将Django项目从本地上传至宝塔服务器(踩坑记录)_django vscode 宝塔上传

django vscode 宝塔上传

自我介绍

自我介绍

⭐2022年度CSDN 社区之星 Top6
⭐2023年度CSDN 博客之星 Top16
⭐2023年度CSDN 城市之星 Top2(苏州)
⭐CSDN Python领域 优质创作者
⭐CSDN 内容合伙人

推荐热门专栏:《趣学Python丨从入门到就业》

写在前面

博主最近用Django搭建了一个有趣的主页,但是在上传至宝塔服务器的时候遇到了一些问题,于是小编写下本篇文章,主要介绍一下如何将本地项目上传至宝塔服务器,以及踩坑记录。

配置本地文件

1.修改项目根目录下的settings文件:

1

DEBUG = False

ALLOWED_HOSTS = ['*',]
CSRF_TRUSTED_ORIGINS = ['项目ip',]
  • 1
  • 2
  • 3
  • 4

以及

2

STATIC_URL = 'static/'
STATIC_ROOT = Path(BASE_DIR).joinpath('static')    # 生产模式
# STATICFILES_DIRS = (
#     Path(BASE_DIR).joinpath("static"),
# )

MEDIA_URL = '/media/'
MEDIA_ROOT = Path(BASE_DIR).joinpath('media/')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

2.在终端输入

python manage.py collectstatic
  • 1

收集静态资源

3.在终端输入

pip freeze > requirements.txt
  • 1

将项目所需库打包

4.打包项目成压缩包,上传至宝塔面板

配置宝塔面板

1.添加python项目

3

2.添加域名→打开外网映射→修改配置文件

4

    location /static/{
      alias /www/wwwroot/Web/WANT/static/;  #static静态文件所在位置
    }
    
    location /media/{
      alias /www/wwwroot/Web/WANT/media/;  #media文件所在位置
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

3.重启项目

解决遇到问题

1.查看日志文件

5

有几个日志文件都可以看看

6

7

2.日志中有如“no module named …”的错误信息,说明缺少相应模块

需要安装对应模块,如果安装后还是报错,我把项目删除后重新添加项目解决了问题(不知道为何)
8

展示运行结果

以下是博主自己写的个人主页:

9

热门文章

序号文章目录直达链接
表白系列
1无法拒绝的表白界面https://want595.blog.csdn.net/article/details/134744894
2满屏飘字表白代码https://want595.blog.csdn.net/article/details/135037388
3无限弹窗表白代码https://want595.blog.csdn.net/article/details/134744711
4李峋同款可写字版跳动的爱心https://want595.blog.csdn.net/article/details/134744191
5流星雨https://want595.blog.csdn.net/article/details/134747408
6漂浮爱心https://want595.blog.csdn.net/article/details/134744929
7爱心光波https://want595.blog.csdn.net/article/details/134747365
8玫瑰花https://want595.blog.csdn.net/article/details/134747447
节日系列
1新春/跨年烟花秀(2022)https://want595.blog.csdn.net/article/details/128727394
烟花秀(2023)https://want595.blog.csdn.net/article/details/135042880
2圣诞节圣诞礼物https://want595.blog.csdn.net/article/details/135336583
圣诞树(2022)https://want595.blog.csdn.net/article/details/128428985
绿色圣诞树(2023)https://want595.blog.csdn.net/article/details/135048607
粉色圣诞树(2023)https://want595.blog.csdn.net/article/details/135043042
3冬至大雪纷飞https://want595.blog.csdn.net/article/details/128806017
4生日生日蛋糕https://want595.blog.csdn.net/article/details/128739755
5儿童节五彩气球https://want595.blog.csdn.net/article/details/128741043
6国庆节国庆祝福https://want595.blog.csdn.net/article/details/128740923
7万圣节万圣礼物https://want595.blog.csdn.net/article/details/128734395
8愚人节愚人代码https://want595.blog.csdn.net/article/details/128696990
9中秋节浪漫星空https://want595.blog.csdn.net/article/details/128737284
10植树节樱花树https://want595.blog.csdn.net/article/details/128700178
动漫系列
1名侦探柯南系列柯南https://want595.blog.csdn.net/article/details/134777613
2喜羊羊与灰太狼系列喜羊羊https://want595.blog.csdn.net/article/details/134778583
懒羊羊https://want595.blog.csdn.net/article/details/134847642
灰太狼https://want595.blog.csdn.net/article/details/135335303
小灰灰https://want595.blog.csdn.net/article/details/135335445
小香香https://want595.blog.csdn.net/article/details/135056783
3海绵宝宝系列海绵宝宝https://want595.blog.csdn.net/article/details/134847364
4哆啦A梦系列哆啦A梦https://want595.blog.csdn.net/article/details/135037884
5HelloKitty系列hellokittyhttps://want595.blog.csdn.net/article/details/135337732
6Tom&Jerry系列Tom&Jerryhttps://want595.blog.csdn.net/article/details/135337775
7草莓熊系列草莓熊https://want595.blog.csdn.net/article/details/135337832
8皮卡丘系列迷你皮卡丘https://want595.blog.csdn.net/article/details/135337911
高级皮卡丘https://want595.blog.csdn.net/article/details/135337937
豪华皮卡丘https://want595.blog.csdn.net/article/details/135337947
炫酷系列
1  一闪一闪亮星星系列张万森下雪了https://want595.blog.csdn.net/article/details/135336915
一闪一闪亮星星https://want595.blog.csdn.net/article/details/135337049
2代码雨https://want595.blog.csdn.net/article/details/135054341
3七彩花朵https://want595.blog.csdn.net/article/details/135056670
43D星空https://want595.blog.csdn.net/article/details/135056516
5金榜题名https://want595.blog.csdn.net/article/details/135056150
6满天星https://want595.blog.csdn.net/article/details/135056305
……
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/186774
推荐阅读
相关标签
  

闽ICP备14008679号