英文:
Django Can't Find a static file that's already there
问题
我在使用Django时遇到了一个非常奇怪的问题。基本上,我在<static/css>目录下有一个CSS静态文件,但终端显示了以下奇怪的消息:“GET /home/.../django/mysite/static/css/style.css HTTP/1.1” 404 1932,而实际上文件是存在的!
设置文件:
DEBUG = True
ALLOWED_HOSTS = ['*']
STATIC_URL = str(BASE_DIR) + '/static/'
STATIC_ROOT = str(BASE_DIR.joinpath('static'))
STATICFILES_DIR = (str(BASE_DIR.joinpath('static')),)
我已经使用了“python manage.py collectstatic”命令,但它没有起作用;我还查看了这个页面:https://docs.djangoproject.com/en/4.2/howto/static-files/,但对我没有解决方案... 请告诉我问题出在哪里!
英文:
I'm facing a very peculiar problem using Django. So basically I have a CSS static file inside <static/css> directory, and here's the strange message from terminal: "GET /home/.../django/mysite/static/css/style.css HTTP/1.1" 404 1932, while the file is actually there!
settings file:
DEBUG = True
ALLOWED_HOSTS = ['*']
STATIC_URL = str(BASE_DIR) + '/static/'
STATIC_ROOT = str(BASE_DIR.joinpath('static'))
STATICFILES_DIR = (str(BASE_DIR.joinpath('static')),)
I have used the command "python manage.py collectstatic", but it didn't work; I also checked out this page: <https://docs.djangoproject.com/en/4.2/howto/static-files/> but there was no solution for me... Please tell me what's wrong!
答案1
得分: 1
尝试将您的STATIC_URL设置如下:
STATIC_URL = 'static/'
您当前是根据项目目录结构构建它,但网页需要它在网站上下文中,例如,domain.com/static/
英文:
try making your STATIC_URL as follows
STATIC_URL = 'static/'
You are currently constructing it out of your project directory structure, but the web page needs it in a website context, eg, domain.com/static/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论