django 1.10 one app page with a link redirect to another app page

8.5k Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

<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