Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

302
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda