3

I'm new to django server and trying to build a simple website for user registration. Here is the problem, I create my own app with index.html as my homepage. I also used another user registration app from:

https://github.com/pennersr/django-allauth/tree/master/allauth

I was trying to add the app to my homepage with a 'sign up' link. Basically, the account part, and ideally, the link can direct to: http://127.0.0.1:8000/accounts/login/

However, when I run the server, it gives me error:

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

server result:

Both apps work fine individually, but when I try to add the link to my homepage, the error occurs.

The related code in index.html file in my first app:

<li><a href="{% url 'allauth:base' %}">Log In</a></li>

The full path for index.html in my project is:

 project/app1/templates/app1/index.html

The full path for base.html in my project is:

 project/allauth/templates/base.html

I know I probably need to add a url line in my first app's urls.py file, and a view to show it, but how can I do it? Can anyone help me with this, much appreciate.

Minwu Yu
  • 311
  • 1
  • 6
  • 24
  • 1
    Do you have to use the other registration app? I mean it is easy enough to use native django authentication system. – Bobby Jan 04 '17 at 03:09
  • I think you're missing the `namespace` keyword in all-auth `include` in your urls settings. – narendra-choudhary Jan 04 '17 at 03:58
  • @Bobby, since I mainly need the email confirmation and the socialaccount function in this app, but yeah, I should try the django auth system first to better understand the concept. – Minwu Yu Jan 04 '17 at 04:24
  • @gitblame, I tried that by giving each app's urls.py a specific app_name, while it caused other reverse issues. – Minwu Yu Jan 04 '17 at 04:26

1 Answers1

0

<li><a href="{% url 'allauth:base' %}">Log In</a></li>

this line uses URL reversing, 'allauth:base' is the URL patterns, allauth prefix is the namespace, base is the named URL. You must define the namespace and named URL in the urls.py first.

Define your namespace in project's urls.py file like this:

from django.conf.urls import include, url

urlpatterns = [
    url(r'^author-polls/', include('polls.urls', namespace='author-polls')),
    url(r'^publisher-polls/', include('polls.urls', namespace='publisher-polls')),
]

Define your named URL in app's urls.py file like this:

from django.conf.urls import url

from . import views

app_name = 'polls'
urlpatterns = [
    url(r'^$', views.IndexView.as_view(), name='index'),
    url(r'^(?P<pk>\d+)/$', views.DetailView.as_view(), name='detail'),
    ...
]

all the help you need is in this document: Naming URL patterns

Easton Lee
  • 30
  • 1
  • 5