Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

309
Views
Django: cómo hacer un enlace en la página principal a las subpáginas

He implementado con éxito algunas páginas que están en urls.py y se puede acceder a ellas sin problemas.
También hay una página predeterminada que debe tener enlaces a 127.0.0.1/page1 y 127.0.0.1/page2 .
¿Cómo podría lograrse eso? el nombre del sitio está en settings.py
He intentado lo siguiente en 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 answers
Answer question

0

Le aconsejo que primero lea este enlace para comprender django url structure https://docs.djangoproject.com/en/1.10/topics/http/urls/#url-namespaces

La solución será así:

 <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>

y debes definir estas urls en urls.py

over 4 years ago · Santiago Trujillo Report

0

Parece que está intentando pasar el nombre de la plantilla a la etiqueta de plantilla de URL. Lo que deberías hacer en realidad es definir el nombre de la URL en tu urls.py, por lo que sería similar a esto:

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

y luego en la plantilla:

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

Debería evitar codificar las URL haciendo algo como esto:

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

porque cuando en el futuro desee cambiar la URL, tendrá que hacerlo en dos lugares: en urls.py y en la(s) plantilla(s), mientras que cuando use la plantilla {% url %}, urls.py será el único lugar para hacerlo.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!