问题描述
我正在A2 Hosting上部署Django网站。
我可以显示页面,但没有加载静态文件(图像/ css)。
我在settings.py中有这个
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')
ROOT_PATH = os.path.dirname(__file__)
STATICFILES_DIRS = [os.path.join(ROOT_PATH,'static')]
我的urls.py:
urlpatterns = [
path('admin/',admin.site.urls),path('',include('mysite.urls')),url(r'^$',TemplateView.as_view(template_name='static_pages/index.html'),name='home'),] + static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
我正在终端中运行python manage.py collectstatic
。它正在创建一个static
文件夹,其文件结构包括该管理文件夹中的admin
和子文件夹。我的图像和CSS文件显示在新生成的static
文件中(在基本文件夹中),而CSS和我的图像均未显示在网页上(我一直在重新启动服务器)。
我的html模板中的CSS文件的链接为:
<link rel="stylesheet" href="{% static 'style.css' %}" type="text/css">
这是在共享主机上完成的,我已将debug设置为false,并且可以在开发中使用。
/home/mysite
->etc
->mysite
-->__pycache__
-->webpage
--->static
---->webpage
----->image.jpg
----->style.css
--->templates
---->webpage
----->index.html
-->main_webpage
--->settings.py
-->public
-->static_files (generated by collectstatic)
--->admin
--->image1
--->style.css
-->template
-->tmp
->logs
...
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)