EDIT : 올바른 사용자 이름과 암호를 입력하면보기가 로그인되지만 잘못된 사용자 이름과 암호를 입력하면 오류가 반환되지 않습니다. 장고에서 제공하는 일반 로그인보기를 사용하고 있습니다. 나는 ". 장고와 협정 출판 학습 웹 사이트 개발"이라는 책에있는 자습서를 수행하고, 이제Django - 일반 로그인보기가 작동하지 않습니다.
<body>
<h1>User Login</h1>
{% if form.has_errors %}
<p>Your username and password did not match.
Please try again.</p>
{% else %}
<form method="post" action=" . ">{% csrf_token %}
<p><label for="id_username">Username:</label>
{{ form.username }}</p>
<p><label for="id_password">Password:</label>
{{ form.password }}</p>
<input type="hidden" name="next" value="/" />
<input type="submit" value="login" />
</form>
{% endif %}
</body>
: 이것은 내 login.html 템플릿입니다. 잘못된 사용자 이름과 암호를 의도적으로 제출하더라도보기는 결코 반환되지 않습니다.
form.has_errors
제출을 클릭하면 나에게 같은 페이지로 계속 돌아옵니다. 또한, 읽은 HTML 책에 따르면 양식의 'action'속성은 정보를 검색 할 서버의 페이지 URL입니다. 그것이 작동하지 않는 이유가 무엇입니까? 왜냐하면 내
action=" . "
?
편집 : 뷰는 일반 로그인 볼 수 있습니다 :
@sensitive_post_parameters()
@csrf_protect
@never_cache
def login(request, template_name='registration/login.html',
redirect_field_name=REDIRECT_FIELD_NAME,
authentication_form=AuthenticationForm,
current_app=None, extra_context=None):
"""
Displays the login form and handles the login action.
"""
redirect_to = request.REQUEST.get(redirect_field_name, '')
if request.method == "POST":
form = authentication_form(data=request.POST)
if form.is_valid():
# Ensure the user-originating redirection url is safe.
if not is_safe_url(url=redirect_to, host=request.get_host()):
redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)
# Okay, security check complete. Log the user in.
auth_login(request, form.get_user())
if request.session.test_cookie_worked():
request.session.delete_test_cookie()
return HttpResponseRedirect(redirect_to)
else:
form = authentication_form(request)
request.session.set_test_cookie()
current_site = get_current_site(request)
context = {
'form': form,
redirect_field_name: redirect_to,
'site': current_site,
'site_name': current_site.name,
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context,
current_app=current_app)
내 urls.py는
url(r'^$', main_page),
url(r'^user/(\w+)/$', user_page),
url(r'^login/$', login),
로 대체'의회 처리는 참으로이 양식을받을하기 위해 당신이 당신의'urls.py'에 정의 된 URL을 가리켜 야합니다. 좀 더 완전한 대답을 위해서는 뷰 코드가 필요합니다. –
https://www.youtube.com/watch?v=GDtHrsq271o&list=PL385A53B00B8B158E&index=29 –
@YerayDiazDiaz 흠 잘 보았습니다. 내 게시물을 편집하여 urls.py 및 로그인보기를 제공했습니다. 액션을 '127.0.0.1/login /'으로 변경해야합니까? – user2719875