I'm developing a Django app in Openshift, but if I want to run my application locally [localhost:8000]
the application doesn't load static files but my HTML templates are loaded and displayed perfectly.
我正在Openshift中开发一个Django应用程序,但如果我想在本地运行我的应用程序[localhost:8000],应用程序不会加载静态文件,但我的HTML模板会被加载并完美显示。
2 个解决方案
#1
0
If you could provide more details or share code, particularly the templates code that work fine and the code in them that doesnt load the static files. Most basic issues could be you are missing the right static file configuration. Or simply missing the template tag {% load staticfiles %}
.
如果您可以提供更多详细信息或共享代码,特别是可以正常工作的模板代码以及不加载静态文件的代码。大多数基本问题可能是您缺少正确的静态文件配置。或者只是缺少模板标签{%load staticfiles%}。
Try: https://docs.djangoproject.com/en/1.9/howto/static-files/
#2
0
So I experienced a similar issue. As mentioned by utkarshmail2052, if you look at the Django docs serving static files during development you'll see the following:
所以我遇到了类似的问题。正如utkarshmail2052所提到的,如果你看一下在开发过程中提供静态文件的Django文档,你会看到以下内容:
In addition to these configuration steps, you’ll also need to actually serve the static files. If you use django.contrib.staticfiles as explained above, runserver will do this automatically when DEBUG is set to True...
除了这些配置步骤之外,您还需要实际提供静态文件。如果您使用django.contrib.staticfiles,如上所述,当DEBUG设置为True时,runserver将自动执行此操作...
So my quick fix was confirming that DEBUG = True in my settings.py file on my local machine. Now when you run python manage.py runserver
django should automatically server the static files on your localhost.
所以我的快速修复是在我的本地机器上的settings.py文件中确认DEBUG = True。现在当你运行python manage.py时,runserver django会自动为你的localhost上的静态文件服务。
Just make sure that DEBUG is false before you deploy your app.
在部署应用程序之前,请确保DEBUG为false。
#1
0
If you could provide more details or share code, particularly the templates code that work fine and the code in them that doesnt load the static files. Most basic issues could be you are missing the right static file configuration. Or simply missing the template tag {% load staticfiles %}
.
如果您可以提供更多详细信息或共享代码,特别是可以正常工作的模板代码以及不加载静态文件的代码。大多数基本问题可能是您缺少正确的静态文件配置。或者只是缺少模板标签{%load staticfiles%}。
Try: https://docs.djangoproject.com/en/1.9/howto/static-files/
#2
0
So I experienced a similar issue. As mentioned by utkarshmail2052, if you look at the Django docs serving static files during development you'll see the following:
所以我遇到了类似的问题。正如utkarshmail2052所提到的,如果你看一下在开发过程中提供静态文件的Django文档,你会看到以下内容:
In addition to these configuration steps, you’ll also need to actually serve the static files. If you use django.contrib.staticfiles as explained above, runserver will do this automatically when DEBUG is set to True...
除了这些配置步骤之外,您还需要实际提供静态文件。如果您使用django.contrib.staticfiles,如上所述,当DEBUG设置为True时,runserver将自动执行此操作...
So my quick fix was confirming that DEBUG = True in my settings.py file on my local machine. Now when you run python manage.py runserver
django should automatically server the static files on your localhost.
所以我的快速修复是在我的本地机器上的settings.py文件中确认DEBUG = True。现在当你运行python manage.py时,runserver django会自动为你的localhost上的静态文件服务。
Just make sure that DEBUG is false before you deploy your app.
在部署应用程序之前,请确保DEBUG为false。