장고 웹 사이트의 로그인 페이지를 만들려고합니다. 처음에는 Django가 제공하는 모든 내장 로그인 함수를 시도했지만 문제가 발생했습니다. 내 문제는, 로그인 페이지가 홈 페이지로 리다이렉션하려고하는 당분간이다. (나는 또 다른 페이지, didnt 작업을 시도했다) 일단 사용자가 로그인하면, 리다이렉트 페이지는 HTML로 렌더링되지만 URL은/mobile/or /로 인해/accounts/login /으로 유지된다. 이 링크가 작동하지 않으며 정적 파일이로드되지 않습니다.Django 로그인은 리디렉션 된 템플릿을 렌더링하지만 로그인 URL에 유지됩니다.
아래는 내 로그인보기 코드입니다 : 내가 그것을 작동 할 수 있습니다 내 자신을 작성한 경우 로그인 화면에서 내장이 작동하는 보이지 않았기 때문에
def login(request):
if request.method == "POST":
redirect_to = request.POST['next']
print 'method is post'
form = AuthenticationForm(data=request.POST)
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = auth.authenticate(username=username, password=password)
if form.is_valid() and user is not None and user.is_active:
print 'form is valid'
netloc = urlparse.urlparse(redirect_to)[1]
print 'original redirect_to is: ',redirect_to
# Use default setting if redirect_to is empty
if not redirect_to:
print 'changing redict to default: ', redirect_to
redirect_to = settings.LOGIN_REDIRECT_URL
print 'redirect to is: ',redirect_to
# Heavier security check -- don't allow redirection to a different
# host.
#elif netloc and netloc != request.get_host():
# redirect_to = settings.LOGIN_REDIRECT_URL
# Okay, security checks complete. Log the user in.
print form.get_user()
auth.login(request, user)
print 'user logged in'
return redirect(reverse('builds.views.mobile_view'))
else:
redirect_to = request.REQUEST.get('next')
form = AuthenticationForm(request)
c = {
'next':redirect_to,
'form': form,
}
print 'returning render to response login'
return TemplateResponse(request,'registration/login.html', context = c)
, 나는 그러나 문제가 지속, 생각.
여기 내 로그인 html 코드입니다 :
<!-- Start of first page: START -->
<div data-role="page" class="type-interior" id="LOGIN" data-theme="a">
{% if form.errors %}
<div data-role="header" data-theme="a" data-content-theme="a">
<h1>Your username and password didn't match. Please try again.</h1>
</div><!-- /header -->
{% else %}
<div data-role="header" data-theme="a" data-content-theme="a">
<h1>Please Enter Your Username and Password</h1>
</div><!-- /header -->
{% endif %}
<form method="post" action="/accounts/login/" id="login_form">
<label for="username">User name:</label>
<input type="text" name="username" value="" id="username">
<label for="password">Password:</label>
<input type="password" name="password" value="" id="password">
<input type="submit" value="Login" id="button"/>
<input type="hidden" name="next" value="{{ next|escape }}" />
</form>
<div data-role="footer" data-theme="a">
<h4></h4>
</div>
</div>
제발 도와주세요! 나는 모든 것을 시도한 것 같은 기분이 든다. 또한 다른 코드를 포함해야하는지 알려주세요.
편집 :
OKAY! 나는 로그인 페이지의 헤더 (jquery를 사용하고있다)에서 사용하고있는 자바 스크립트 내용에이 문제를 좁혔다. 헤더는 다음과 같습니다.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>Install Builds</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="{{ STATIC_URL }}blablahblachname.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile.structure-1.1.0.min.css" />
<!--<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>-->
<link rel="apple-touch-icon-precomposed" href="{{ STATIC_URL }}static/homepage_icon.png" />
<link rel="icon" href="{{ STATIC_URL }}homepage_icon.png" type="image/vnd.microsoft.icon" />
</head>
해결 방법이 있습니까? 또는 자바 스크립트를 완전히 제외해야하므로 로그인 페이지가 번거롭습니까? (
감사합니다. – karkle