R
R
Ruslan Bergutov2015-04-27 14:48:10
Django
Ruslan Bergutov, 2015-04-27 14:48:10

How are links defined in Django?

There is such a html navigation (so far only layout)

<ul class="nav navbar-nav">
                            <li class="active"><a href="index">Главная<span class="sr-only">(current)</span></a></li>
                            <li class="dropdown">
                                <a href="blog" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">О нас<span class="caret"></span></a>
                                <ul class="dropdown-menu" role="menu">
                                    <li><a href="about.html">О нас</a></li>
                                    <li><a href="photo.html">Фото</a></li>
                                    <li><a href="blog">Блог</a></li>
                                </ul>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Цены <span class="caret"></span></a>
                                <ul class="dropdown-menu" role="menu">
                                    <li><a href="#">Прайс-лист</a></li>
                                    <li><a href="#">Наши услуги</a></li>
                                </ul>
                            </li>
                            <li><a href="contacts.html">Контакты</a></li>
                        </ul>

How is the link between templates set in django? For example, being on the blog page and clicking on the main page, it does not redirect to index, it adds index to the general line and it turns out something like mysite/blog/index
Version Django 1.8, Python 3.4

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2015-04-27
@sim3x

The MVT methodology assumes the maximum separation of the
Template entities only shows, then it orders to show the View, which in turn takes data from the Model.
You need to write the View resolving rules in urls.py

# ....
url(r'^$', index_view, name='index'),
# ...

in app/views.py write views that call templates/*.html
def index_view(request):
    return render(request, 'index.html')

Then in the template
...
<a href="{% url "index" %}">
...

Y
Yuri Shikanov, 2015-04-27
@dizballanze

Django has nothing to do with it, just specify addresses starting with /: /indexand so on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question