Trying to link to a different url in a Django app.

hello, Still new to Django and I am using Django 5.0 and Python 3.11 to attempt a map sit (eventually with leaflet). I want the “mainmenu” to launch a page from the selection of the user. The “App” model has the “app.name” and the “app.pagelink”. I am unable to get out of the members app. Similar to this: Redirect to a different app

I have 3 apps inside the project, jobinfo, members and booking. The url.py in the project (maps_proj) is

from django.contrib import admin
from django.urls import path, include

admin.site.site_header = "Administration Page"
admin.site.site_title = "SSI Database"
admin.site.index_title = "SSI Map Admin"

urlpatterns = [
    path("admin/", admin.site.urls),
    path("signin/", include("members.urls")),
    path("", include("members.urls")),
    path('jobinfo/', include("jobinfo.urls"))
    
]

my signin page in the “members” app works fine and launches the

The members url.py

from django.urls import path

from . import views

urlpatterns = [
    path("", views.signin, name="signin"),
    path("mainmenu/", views.mainmenu, name="mainmenu"),
    path("mainmenu/jobinfo/", views.jobinfo, name="mainjob"),
]

The jobinfo urls.py is:

from django.urls import path
from jobinfo.views import MarkersMapView
from . import views

urlpatterns = [
    path("jobinfo/", views.jobinfo, name="jobinfo"),
    path( "jobinfo/map/", MarkersMapView.as_view(), name='jobmap' ),
]

the html to make the jump/link is:

 {% for app in all_apps %}       
          <!-- <li onclick="window.location = '{{app.pagelink}}'">{{app.name}}</li> -->
          <li onclick="window.location = '{{app.pagelink}}'">{{app.name}}</li>
      {% endfor %}

I have swapped out the text in the html > ‘{{app.pagelink}}’ to many things to try and not use the variable and hard code something here. What is the correct syntax to get to a view in the jobinfo app?

Any help is always appreciated.

You don’t direct or redirect to an app or a view. You redirect to a url. See the url tag

1 Like

Yes, thanks. My url path inside the jobinfo app is
path("jobinfo/", views.jobinfo, name="jobinfo"),

Seeing this post:

How to create href link from one Django app to another - Stack Overflow

When I change my HTML to include the name " jobinfo" like this:

<li onclick="window.location = '{% url jobinfo%}'" >{{app.name}}</li>

I get the error:

NoReverseMatch at /mainmenu/>

Reverse for ‘’ not found. ‘’ is not a valid view function or pattern name.

Side note: S.O. has zero credibility from my perspective - I’ve written many times here about how dangerous and damaging it can be to someone trying to learn something new. If you want to use it as the starting point for your research, great. But it’s not a reference to be relied upon without independent verification.

At this point in your template:

Is the jobinfo here a variable in your context or a literal string? (The difference between the two and why it matters is covered in the docs. Also see the warning box in that section.)

1 Like

Thanks Ken, jobinfo is just a place holder for now. I will put anything in there that will make it to the app url path jobinfo in the jobinfo app. my variable was '{{app.pagelink}}' and the model (app) has the field “pagelink” which I hoped to pass with the variable but I wanted to make it simple first.

I was looking at URL dispatcher | Django documentation | Django but I cannot seem to get out of the app I am in “members”. All url requests start with “members”

I added the app_name = ‘jobinfo’ and that helped a bunch. I’ll post my modified code shortly. It’s working although very ugly at the moment.