2
In the menu of the template I have a menu Dropdown
with the links to the other pages
of the app!
In the menu of the home page of the application I have the links to the other pages of the application! Ex: Home, Reports, About... All are link’s that when clicking should direct to the respective pages.
To handle this redirect I added in the tags <a>
from my base template an onclik function that redirects to the appropriate pages.
The dropdown menu code looks like this:
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Serviços <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#" onclick="window.location='http://localhost:8000/cadLivro';">Cadastrar Livros</a></li>
<li><a href="#" onclick="window.location='http://localhost:8000/cadUsuario';">Cadastrar Usuários</a></li>
<li><a href="#" onclick="window.location='http://localhost:8000/cadFuncionario';">Cadastrar Funcionários</a></li>
<li class="divider"></li>
<li class="dropdown-header">Pesquisa</li>
<li><a href="#" onclick="window.location='http://localhost:8000/pesqLivro';">Livro</a></li>
<li><a href="#" onclick="window.location='http://localhost:8000/pesqUsuario';">Usuário</a></li>
<li><a href="#" onclick="window.location='http://localhost:8000/pesqFuncionario';">Funcionário</a></li>
</ul>
</li>
That’s what I was able to do, because I don’t have much knowledge of javascript (much less jQuery), what I did is a "gambiarra" and would only work if I were to run the application locally and at port 8000. How do I redirect this in a correct way ?!
How’s your Javascript code and your
urls.py
? It is difficult to understand what is your question only with what is being asked, please add more details to your question.– mgibsonbr
In the menu of the home page of the application I have the links to the other pages of the application! Ex: Home, Reports, About... All are link’s that when clicking should direct to the respective pages. It turns out that as I have not referenced these links in html nor have JS functions to handle. I wonder if in Django I can treat this event by clicking on the links so that by clicking it leads me to the pages!
– water
Basically, you can put whatever you want in HTML/Javascript, which pro Django only matters is that the final URL has a corresponding entry in
urls.py
. If this is done through a direct link, from Ajax, vialocation.href
,new Window
, doesn’t matter... In the same way, what your functiononclick
does not concern Django, it is all on the client side even. If you are having problems, probably is a simple poorly constructed URL, show the code (the relevant section of the template) we may be able to help you better.– mgibsonbr
Ex.: I saw on your Github link that each link has one
href
the kind#cadLivros
,#cadUsuarios
etc. You could at first put a Javascript code that would transform these fragments into complete Urls. But that’s all on the client side, there’s nothing in Django I can help you with that.– mgibsonbr
rephrased question
– water
Now, yes, I understand what your question is! I voted for the reopening, when that happens put an answer. For now, I leave this link on Soen showing how to do.
– mgibsonbr
I still don’t understand what you’re trying to do, onclick inside a tag
<a>
? Why not put the direct address in the attributehref
?– Paulo