【发布时间】:2015-11-12 19:53:31
【问题描述】:
我是 Python 和 Django 的初学者,一直在努力解决以下问题:
在 localhost:8000/ webiste 上很漂亮并且工作正常,但在 localhost:8000/invoice/ 上,一些引用不起作用。例如,CSS 不起作用,但图像和 JavaScript 可以。
我正在使用相对链接来指出我的路径在哪里。
<script src="{% static "js/jquery.min.js" %}"></script>
<script src="{% static "js/skel.min.js" %}"></script>
<script src="{% static "js/skel-layers.min.js" %}"></script>
<script src="{% static "js/init.js" %}"></script>
<noscript>
<link rel="stylesheet" href="{% static "css/skel.css" %}"/>
<link rel="stylesheet" href="{% static "css/style.css" %}"/>
<link rel="stylesheet" href="{% static "css/style-xlarge.css" %}"/>
</noscript>
<img src="{% static "images/pic07.jpg" %}" alt="" />
Settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static/"),
)
查看.py
def home(request):
return render(request, 'principal.html',)
def invoice(request):
return render(request, 'invoice.html',)
当我使用浏览器检查页面代码时,我看到链接被称为http://localhost:8000/invoice/static/css/somecss.css。
invoice.html 在 /project/folder/templates/ 内,而我的 .css 在 /project/static/css/ 内。 invoice.html 位于我的 index.html (principal.html) 页面的同一个文件夹中,该页面正在运行。
此外,网站/发票/页面内的所有链接都变为网站/发票/链接而不是网站/链接
【问题讨论】:
-
什么CSS?您的示例实际上没有显示任何内容...请提供minimal reproducible example
-
其实你使用的是django框架,而不仅仅是“python”。 invoice.html 在哪里?
-
invoice.html 在 project/folder/templates/ 内,而我的 .css 在 /project/static/css/ 内。 invoice.html 位于我的 index.html 页面所在的同一文件夹中,该页面正在运行。
-
我已经删除了
标签: python css django reference