diff --git a/taxi/urls.py b/taxi/urls.py index a159172a..a7226d8d 100644 --- a/taxi/urls.py +++ b/taxi/urls.py @@ -6,7 +6,7 @@ CarDetailView, DriverListView, DriverDetailView, - ManufacturerListView, login_view, logout_view, + ManufacturerListView ) urlpatterns = [ @@ -22,8 +22,6 @@ path( "drivers//", DriverDetailView.as_view(), name="driver-detail" ), - path("accounts/login/", login_view, name="login"), - path("accounts/logout/", logout_view, name="logout"), ] app_name = "taxi" diff --git a/taxi/views.py b/taxi/views.py index da2ca6bf..0c80c851 100644 --- a/taxi/views.py +++ b/taxi/views.py @@ -53,23 +53,3 @@ class DriverListView(LoginRequiredMixin, generic.ListView): class DriverDetailView(LoginRequiredMixin, generic.DetailView): model = Driver queryset = Driver.objects.prefetch_related("cars__manufacturer") - - -def login_view(request: HttpRequest) -> HttpResponse: - if request.method == "GET": - form = AuthenticationForm() - return render(request, "registration/login.html", {"form": form}) - elif request.method == "POST": - form = AuthenticationForm(data=request.POST) - if form.is_valid(): - user = form.get_user() - login(request, user) - return HttpResponseRedirect(reverse("taxi:index")) - else: - return render(request, "registration/login.html", {"form": form}) - - -def logout_view(request) -> HttpResponse: - form = AuthenticationForm() - logout(request) - return render(request, "registration/logged_out.html", {"form": form}) diff --git a/taxi_service/urls.py b/taxi_service/urls.py index cc567bbe..bdd8775f 100644 --- a/taxi_service/urls.py +++ b/taxi_service/urls.py @@ -2,10 +2,15 @@ from django.conf.urls.static import static from django.contrib import admin from django.urls import path, include -from debug_toolbar.toolbar import debug_toolbar_urls urlpatterns = [ path("admin/", admin.site.urls), path("", include("taxi.urls", namespace="taxi")), path("accounts/", include("django.contrib.auth.urls")), ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + +if settings.DEBUG: + import debug_toolbar + urlpatterns = [ + path('__debug__/', include(debug_toolbar.urls)), + ] + urlpatterns diff --git a/templates/registration/login.html b/templates/registration/login.html index 2b7d14fe..ce4f6733 100644 --- a/templates/registration/login.html +++ b/templates/registration/login.html @@ -4,7 +4,7 @@

Login

{% if form.errors %}

Invalid credentials

{% endif %} -
+ {% csrf_token %} {{ form.as_p }}