簡體   English   中英

Django static 生產文件故障排除

[英]Django static files troubleshooting for production

BASE_DIR = Path(__file__).resolve().parent.parent

DEBUG = False

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

INSTALLED_APPS has 'django.contrib.staticfiles'

This is how they're called in HTML
<img src="{% static 'capabilities-2.jpg' %}" class="img-fluid">

Displayed in my console:
[10/Sep/2022 17:39:50] "GET /css/index_styles.css HTTP/1.1" 404 179
[10/Sep/2022 17:39:50] "GET /js/scripts.js HTTP/1.1" 404 179
[10/Sep/2022 17:39:51] "GET /static/index/images/capabilities-2.jpg HTTP/1.1" 404 179
[10/Sep/2022 17:39:51] "GET /assets/favicon.ico HTTP/1.1" 404 179

試圖從開發過渡到生產。 我讓圖像在開發中工作。

如果我在瀏覽器中檢查圖像(或缺少圖像),路徑如下:

應該注意的是,在檢查源代碼時我什至看不到它們。

我嘗試將路徑 /static/capabilities-2.jpg 調整為 /static/index/images/capabilities-2.jpg ,因為它在我的項目中,但仍然沒有用。

我在 Linode 上運行,Ubuntu 22.04。 我非常喜歡 Django,但是 static 文件是一個巨大的 PIMA。

Django static 文件服務器僅供開發期間使用。 在生產期間,使用您的網絡服務器的 static 文件功能:

或者,如果您使用的是不同的,請查看文檔和/或谷歌它。

開發環境用於創建項目。 生產環境是托管公共網站的服務器(或服務器)。 對於生產,一些選擇:

How to store static media? For example, Amazon S3 or CloudFront.
Which OS and distribution? For example, Debian, Red Hat, or OpenBSD.
Which WSGI server? For example, Gunicorn or uWSGI.
Which webserver? For example, Apache or Nginx.
Which database? For example, PostgreSQL, MySQL, or Redis.
Which caching system? For example, Memcached or Redis.
Which process control and monitoring system? For example, Upstart,
Systemd, or Supervisord.

更多信息: https://simpleisbetterthancomplex.com/tutorial/2021/06/27/how-to-start-a-production-ready-django-project.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM