python - 每当我尝试加载静态文件时,它都会给出错误 404 not found
问题描述
每当我尝试加载静态文件时,它都会给出错误 404 not found。但是,当检查它在哪个目录中显示时,它会显示 /account/login/static/accounts/style.css,而 account/login 甚至不是目录。错误消息未找到:/account/login/static/accounts/style.css
我到处搜索,找不到如何更改目录。
这是 settings.py 文件:
STATIC_URL = '/static/'
LOGIN_REDIRECT_URL = '/accounts'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
这是我的帐户/urls.py:
from django.contrib.auth.views import LoginView
from django.urls import path
from accounts import views
app_name = "users"
urlpatterns = [
path('', views.home, name='home'),
path('login/', LoginView.as_view(template_name='accounts/login.html'), name="login")
]
这是我的教程/urls.py:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('account/', include('accounts.urls'))
]
这是我的view.py:
from django.shortcuts import render, HttpResponse
def home(request):
return render(r[enter image description here][1]equest, "accounts/login.html")[enter image description here][1]
这是我的目录/文件的图像:https ://i.stack.imgur.com/vdk0X.png
解决方案
运行命令:
python manage.py runserver
然后从您的模板地址中清除该帐户前缀。
将此更改为此accounts/login.html
,login.html
您应该在模板文件 login.html 中进行更多更改以加载静态文件。我建议您先阅读文档。
推荐阅读
- django - 带有空参数的 django 模板 url 标签
- r - doParallel::makeCluster 导致“未能发现安全下载方法”。错误
- sharepoint-online - 如何使用 C# 通过 microsoft graph 获取所有子站点?
- node.js - Ng 服务器 - Angular 服务器未启动
- python - 使用 beautifulSoup抓取文本时结果为空
- javascript - 转换没有时区的日期格式 - Google 应用脚本 (Javascript)、Google 电子表格
- javascript - 如何使用 mocha、chai 和量角器等待元素
- html - 如何阻止 mat-table 调整其列的大小?
- machine-learning - Pytorch DataLoader 流水线
- vega-lite - 在悬停/选择时更改 vega lite 密度图颜色