creating a loginpage

46 views
Skip to first unread message

Timothy Steele

unread,
Sep 14, 2016, 11:44:14 AM9/14/16
to Django users
Instead of providing the view itself, i want to  pass its module path as a string in the urls.py file  as the code below


urlpatterns = ['',
     url(r'^$', main_page),
     url(r'^user/(\w+)/$', user_page),
     url(r'^login/$', 'django.contrib.auth.views.login'),
]

but it return this information
TypeError: view must be a callable or a list/tuple in the case of include()


please any help

below is also the HTML form .
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Django Bookmark - User Login</title>
</head>
<body>
<h1>User Login</h1>
{% if form.has_errors %}
<p>Your username and password didn't match.</p>

{% endif %}
<form method="post" action=".">
<p><label for="id_username">Username:</label>{{ form.username }}</p>
<p><label for="id_password">Password:</label>{{ form.password }}</p>
<input type="hidden" name="next" value="/"/>
<input type="submit" value="login"/>
</form>
</body>
</html>

Tim Graham

unread,
Sep 14, 2016, 1:26:17 PM9/14/16
to Django users
Import the view: from django.contrib.auth.views import login
and replace 'django.contrib.auth.views.login' with a reference to the login function.

from django.contrib.auth.views import login

urlpatterns = [ <-- remove the empty string on this line
     ...
     url(r'^login/$', login),
]

Andrea D'Amore

unread,
Sep 14, 2016, 1:50:12 PM9/14/16
to django...@googlegroups.com
On 14 September 2016 at 17:44, Timothy Steele
<steeleti...@gmail.com> wrote:
> Instead of providing the view itself, i want to pass its module path as a
> string in the urls.py file as the code below
>
> urlpatterns = ['',
> url(r'^$', main_page),
> url(r'^user/(\w+)/$', user_page),
> url(r'^login/$', 'django.contrib.auth.views.login'),
> ]

Use include() [1] for that, there are further info at [2] including a
shorthand for registering several urls at once and a login form
template.


[1]: https://docs.djangoproject.com/en/1.10/ref/urls/#include
[2]: https://docs.djangoproject.com/en/1.10/topics/auth/default/

--
Andrea

Timothy Steele

unread,
Sep 14, 2016, 2:13:24 PM9/14/16
to Django users
Tim Graham, I did it but i get back this error login() missing 1 required positional argument: 'user' 

Timothy Steele

unread,
Sep 14, 2016, 2:22:18 PM9/14/16
to Django users
Thanks Tim it has work this time but can any one help me with a beginner book to learn Django please



On Wednesday, September 14, 2016 at 4:44:14 PM UTC+1, Timothy Steele wrote:

Tim Graham

unread,
Sep 14, 2016, 9:30:25 PM9/14/16
to Django users
Have you looked at the official Django documentation?

http://masteringdjango.com/django-book/ is another nice resource.

Shubham Aggarwal

unread,
Sep 15, 2016, 6:53:55 AM9/15/16
to django...@googlegroups.com
I think Django documentation is well written

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/056f8dd1-258e-49de-b6af-63c7ab5807ff%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Shubham Aggarwal
Reply all
Reply to author
Forward
0 new messages