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

发布时间:2024年01月05日

自我介绍

自我介绍

?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',]

以及

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/')

2.在终端输入

python manage.py collectstatic

收集静态资源
?
3.在终端输入

pip freeze > requirements.txt

将项目所需库打包

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

配置宝塔面板

1.添加python项目

3

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

4

    location /static/{
      alias /www/wwwroot/Web/WANT/static/;  #static静态文件所在位置
    }
    
    location /media/{
      alias /www/wwwroot/Web/WANT/media/;  #media文件所在位置
    }

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
……
文章来源:https://blog.csdn.net/m0_68111267/article/details/135417771
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。