简体   繁体   English

静态图像未在Django项目上加载

[英]Static Images not Loading on Django Project

I just had to restart my app from scratch (at least from setup point of view) due to a migration issue which seemed to mess up my whole db. 由于迁移问题(似乎弄乱了我的整个数据库),我只需要从头开始重新启动应用程序(至少从安装角度而言)。

Anyway, my problem now is with my img and css directories not loading at all. 无论如何,我现在的问题是我的imgcss目录根本没有加载。

I've verified the urls.py is working fine, as I can access urls specified in there, but no images, css, etc. are showing up. 我已经验证urls.py可以正常工作,因为我可以访问其中指定的url,但是没有显示图像,css等。

In settings.py I have: 在settings.py中,我有:

STATIC_ROOT = '/Users/c0de/appWs/git/djangoapp/MyApp/MyApp/Scanner/static/'
PROJECT_ROOT_LOCAL = "/Users/c0de/MyAppWs/git/djangoapp/MyApp/MyApp/"
STATIC_URL = '/static/'
STATICFILES_DIRS = ()
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'django.template.loaders.eggs.Loader',
)
TEMPLATE_DIRS = (
    os.path.join(PROJECT_ROOT_LOCAL, 'Scanner/templates/'),
)

INSTALLED_APPS = (
    #django-default apps
    'MyApp',
)

In my templates, I'm doing calls like: 在我的模板中,我正在进行如下调用:

 <img src="{% static "img/templated/home/img.png" %}" width="85" height="85" alt="img" />

templates and static dir are at this path: templatesstatic目录位于此路径:

/Users/c0de/appWs/git/djangoapp/MyApp/MyApp/Scanner/templates/
/Users/c0de/appWs/git/djangoapp/MyApp/MyApp/Scanner/static/

I've also tried restarting my local default-django server. 我也尝试过重新启动本地的default-django服务器。

Any ideas? 有任何想法吗? Thank you! 谢谢!

Silly, silly me. 傻,傻我。

All this time I thought it was an issue with the paths of STATIC_ROOT or TEMPLATE_DIRS or STATIC_URL 我一直都以为这是STATIC_ROOTTEMPLATE_DIRSSTATIC_URL的路径的问题

It came down to loading not the application, but the project in INSTALLED_APPS . 归结为不是加载应用程序,而是加载INSTALLED_APPS的项目。 It still seems strange it would show the whole application, but not the img or css files, but still lload the template. 它会显示整个应用程序,但不是imgcss文件,但仍然加载模板,这似乎仍然很奇怪。

Now that the actual application is set in INSTALLED_APPS() and not the project (containing this application) this seems to be working fine. 现在,实际的application是在INSTALLED_APPS()设置的,而不是在project (包含此应用程序)中设置的,这似乎运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM