Django — 无法加载静态 CSS 文件

我试图在索引中链接什么.html


<link rel="stylesheet" href="{% static 'assets/css/main.css' %}"/>

我也做过{%负载静态%}


我的文件结构是这样的:


signup/static/assets/css/main.css

settings.py


STATIC_URL = 'signup/static/'


STATICFILES_DIRS = [

    os.path.join(BASE_DIR, 'static'),

]

错误:


[29/Feb/2020 17:19:31] "POST /postsign/ HTTP/1.1" 200 3445

Not Found: /postsign/signup/static/assets/css/main.css

我不明白那个/postign/是从哪里来的


我的 urls.py 是这样的:


urlpatterns = [

    path('admin/', admin.site.urls),

    path('', views.signIn),

    path('postsign/', views.postsign),

    path('logout/', views.logout, name="log"),

    path('signup/', views.signUp, name="signup"),

    path('postsignup/', views.postsignup, name="postsignup"),

    path('profile/', views.profile, name="prof"),

]


后签名方法是:


def postsign(request):

    email = request.POST.get('Email')

    passw = request.POST.get("Password")

    try:

        user = authe.sign_in_with_email_and_password(email, passw)

    except:

        message = "Invalid Username or Password"

        return render(request, "signin.html", {"messg": message})

    print(user['idToken'])

    session_id = user['idToken']

    request.session['uid'] = str(session_id)

    return render(request, "index.html")

Django 版本 3.0.3 如果有帮助


慕盖茨4494581
浏览 87回答 2
2回答

Qyouu

添加前导斜杠 to 以避免静态 URL 是相对的:STATIC_URLSTATIC_URL&nbsp;=&nbsp;'/signup/static/'

米脂

将以下内容添加到您的URL patternsfrom django.conf.urls.static import staticurlpatterns = [...] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)`
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python