Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

304
Vistas
Django: how to make a link on main page to sub-pages

I have had successfully deployed some pages which are in urls.py and could be reached with no problems.
There is also default page should have links to 127.0.0.1/page1 and 127.0.0.1/page2.
How could that be achieved? sitename is in settings.py
I have tried the following in index.html:

<h3>This is the URL for "page1": <a href="{% url 'sitename:page1.html' %}"> Click here</a></h3>
> django.urls.exceptions.NoReverseMatch: 'sitename' is not a registered namespace

<h3>This is the URL for "page1": <a href="{% url 'page1.html' %}"> Click here</a></h3>
> Reverse for 'exp.html' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

I advice you first read this link for understanding django url structure https://docs.djangoproject.com/en/1.10/topics/http/urls/#url-namespaces

The Solution will be like that:

<h3>This is the URL for "page1": <a href="/page1"> Click here</a></h3>

<h3>This is the URL for "page2": <a href="/page2"> Click here</a></h3>

and you must define this urls in urls.py

over 4 years ago · Santiago Trujillo Denunciar

0

It looks like you're trying to pass template name to url template tag. What you should actually do is to define url name in your urls.py, so it would look similiar to this:

url(r'^page1/$', YourView.as_view(), name="page1")

and then in template:

<a href="{% url "page1" %}">Page 1</a>

You should rather avoid hardcoding urls doing something like this:

<a href="/page1">Page 1</a>

because when in future you'd like to change the url you'll have to do it in two places: in urls.py and in template(s), while when using {% url %} template urls.py will be the only place to do it.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda