Pass the guide from the book on the framework Django. The book is 2017, but there are already some differences in versions, which during the implementation of the project make themselves felt, but this is generally solved. The manual has come to authorization of users. Actually, the following code is proposed:

Urls.py:

from django.conf.urls import url from django.contrib.auth.views import login from . import views app_name = "users" urlpatterns = [ url(r'^login/$', login, {'template_name': 'users/login.html'}, name='login'), ] 

Fix django.contrib.auth.views, removing "views". The server starts and I get a response:

TypeError at / users / login /

login () got an unexpected keyword argument 'template_name'

I look through the ways to solve the problem on the Internet, I come across the opportunity to change the import and the path to the following:

 from django.contrib.auth.views import LoginView urlpatterns = [ url(r'^login/$', LoginView, {'template_name': 'users/login.html'}, name='login'), ] 

Already for this, I get the following error:

TypeError at / users / login /

init () takes 1 positional argument but 2 were given

And here I have a stupor and I can not figure it out. Tell me, please, from what should I make a start in resolving the situation?

  • one
    I barely worked with django, but now I looked through the documentation - maybe you need to use LoginView.as_view instead of LoginView? It just has an argument template_name. - Xander
  • Yes thanks a lot! Pushed the answer to the right decision. Imported "from django.contrib.auth import views as auth_views" and "from django.urls import path", and then changed the path to: path ('login /', auth_views.LoginView.as_view (template_name = 'users / login.html '), name =' login '), - rolkins

0