我無法訪問http://localhost:8000/accounts/profile
。當我訪問這個地址時,它會發送給我http://localhost:8000/accounts/login/?next=/accounts/profile/
。我真的不明白爲什麼。我寫在urls.py
。我無法訪問http:// localhost:8000/accounts/profile
urlpatterns = [
url(r'^detail$', views.detail,name='detail'),
url(r'^login/$', views.login,name='login'),
url(r'^profile/$', views.profile, name='profile'),
]
在views.py
def login(request):
login_form = LoginForm(request.POST)
regist_form = RegisterForm(request.POST)
if regist_form.is_valid():
user = regist_form.save(commit=False)
context = {
'user': request.user,
'login_form': login_form,
'regist_form': regist_form,
}
return redirect('profile', context)
if login_form.is_valid():
user = login_form.save(commit=False)
login(request, user)
context = {
'user': request.user,
'login_form': login_form,
'regist_form': regist_form,
}
return redirect('profile', context)
context = {
'login_form': login_form,
'regist_form': regist_form,
}
return render(request, 'registration/accounts/login.html', context)
def profile(request):
context = {
'user': request.user,
}
return render(request, 'registration/accounts/profile.html', context)
在HTML
<main>
<div class="container">
<div class="detailimg col-xs-12">
<img class="small_img" src="{% static 'detail.jpg' %}" alt="Detail" />
<div class="absolute-fill vertical-center-container">
<p class="hthree">XXX
<span class="hthree_small">
<br>YYY
<br>ZZZ</span>
</p>
</div>
</div>
<div class="bodyele col-xs-12">
<a class="button-primary" href="{% url 'accounts:profile' %}">Profile</a>
<a class="button-primary" href="{% url 'accounts:kenshinresults' %}">See</a>
<a class="button-primary" href="{% url 'accounts:kenshinresults' %}">Know</a>
</div>
</div>
</main>
當我把檔案標籤,這種情況發生。我的代碼有什麼問題? urls.py
,views.py
& html是在帳戶中。
我在這些代碼中寫道,但同樣的錯誤發生。我該怎麼做? – user8681386