How can I get {% url logout %} to work in my Django template?

Saqib Ali

My Django app's site-wide urls.py file looks like this:

urlpatterns = patterns('',
    url(r'^$', include('myApp.urls')),
    url(r'^admin/', include(admin.site.urls)),
    url (
        r'^accounts/register/$', 
        RegistrationView.as_view(form_class=extendedRegistrationForm),
    ),  
    url(r'^accounts/', include('registration.backends.default.urls')),
    url(r'^', include('myApp.urls')),
)

I also have a urls.py specific to myApp but I have not shown that here because I don't think it's relevant.

In my template file, I have this:

{% url logout %}

It gives me this error:

'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.

When I change the template to:

{% url 'logout' %}

It gives me the following error:

Reverse for 'logout' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

How do I put a link to logout in my view?

RemcoGerlich

You didn't include django.contrib.auth's URLs in your urls.py, so there is no logout URL.

Try adding something like

url(r'^auth/', include('django.contrib.auth.urls')),

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I get static files to work in my Django project?

My css file doesn't work properly on my django template! How can I fix it?

How can I get the domain name of my site within a Django template?

How can I get the url of a Django ImageField?

(How) can I tell if my form field is hidden in Django template

How can I use Django DeleteView in my template

How can I count my followers in django template?

How can I have a template folder outside my Django project

How can I get AWS Cognito login/logout to work properly with AWS API Gateway on Android?

How to implement logout in django in template?

How can i get values of JSONfield in my template

How can I get index of list in django template

How can I get and display ForeignKey data in a Django template

How can I get first value in a dictionary in django template?

Django : How can I update my views? url problem

How can I use URL in my html page in django?

How can I get my animation to work in the other direction also?

How can I get my 5G wifi to work?

How can I get my sharedpreferences to work correctly?

How can I get my Ionic 4 Typescript paths to work?

How can I get my trampoline script to work?

How can I get my keydown event to work?

How can I get my binary tree insert function to work?

How can I get my CSS media queries to work?

How can I add a logout button to my UITabBar

How can I make my application logout when the browser is closed?

How can I get Django REST Authentication to work?

how can i get json object data in my url in vuejs

How can I get the URL of my image in Picasso