How do I reference a path (URL) in Django? But this path is not in the base app, but in another app

In the base app, which I call it "mywebsite" (the one that contains the settings of the django project), has the file. But I do not want to reference this file, I want to reference a in another app, which I call it "account".

For the base file, I would reference as {% url'login' %}, for example. How do I reference to the other one? Maybe {% account.url 'login' %}?

I tried {% account.url 'login' %} and {% account/url 'login' %}

Never mind, I just added to the base file: path('', include("account.urls"))

I see that you already answered your question, but with no further details or explanations. I'll provide the context needed.

You have a project package. This folders contains files that affect all the application (the website, not just an app). Inside we have the following files: settings, wsgi, asgi and urls.

In the (also called URLconf module) file you control the routing of your application, that is, the mapping between URL path expressions to Python functions (your views).

The Django frameworks knows where to look up for this file because it's stablished in the file:

ROOT_URLCONF = 'django_project.urls'

This is the process (from the docs)

  1. Django determines the root URLconf module to use. Ordinarily, this is the value of the ROOT_URLCONF setting...
  2. Django loads that Python module and looks for the variable urlpatterns. This should be a sequence of django.urls.path() and/or django.urls.re_path() instances.
  3. Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL, matching against path_info.
  4. Once one of the URL patterns matches, Django imports and calls the given view, which is a Python function (or a class-based view)...

But you also have apps, besides the project package. Each app can also have a URLconf module (app/

To Django to know the routing to this apps, you have to include them in the global file (from the project package).

How do you do it? With the include() function. As you mentioned in your own answer, the code is:

from django.urls import include, path

urlpatterns = [
    path('', include("account.urls")),

You're including the accounts paths into the global URLconf module. So when the user types he will access the accounts app routes.

from django.urls import include, path

urlpatterns = [
    path('accounts/', include("account.urls")),

If instead you did like this, the user should type:

Back to Top