1
私はソーシャルメディアサイトを開発するためのコードを書いています。その中で、私はホームページにリダイレクトしたいと思っていました。このページのURLを作成しようとしましたが、使用しません。私はこのようなエラーを受けています:reverse_lazyを使用して静的なWebページをリンクできません
NoReverseMatch at /accounts/signup/
Reverse for 'start' not found. 'start' is not a valid view function or pattern name.
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/signup/
Django Version: 1.11.7
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'start' not found. 'start' is not a valid view function or pattern name.
このプロジェクトでは、3つのアプリケーションがあります。そのうち、「アカウント」は1つのアプリです。アカウントでは、3つのファイル( "login.html、signup.html and start.html")でテンプレートフォルダを作成しました。このためviews.pyファイル:
from django.contrib.auth import login, logout
from django.core.urlresolvers import reverse_lazy
from django.views.generic import CreateView
from . import forms
from django.views.generic import TemplateView
class MyView(TemplateView):
template_name = 'accounts/start.html'
class SignUp(CreateView):
form_class = forms.UserCreateForm
success_url = reverse_lazy("start")
template_name = "accounts/signup.html"
そしてurls.pyファイルは次のとおりです。
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from . import views
app_name = 'accounts'
urlpatterns = [
url(r"login/$", auth_views.LoginView.as_view(template_name="accounts/login.html"),name='login'),
url(r"logout/$", auth_views.LogoutView.as_view(), name="logout"),
url(r"signup/$", views.SignUp.as_view(), name="signup"),
url(r"start/$", views.MyView.as_view(), name="start")
]
登録ページから "start.htmlここ" ページにリダイレクトする方法。私はスタートビューを作成しましたが、上記のようにエラーを表示しています。これで私を助けてください。パターンの終わりのためのパターン開始の
ありがとうございます。 @Ykh。なぜ以前にはうまくいかなかったのですか? –
https://docs.djangoproject.com/en/1.11/topics/http/urls/#reversing-namespaced-urls – Ykh