M
M
Maxemp2017-09-02 18:52:23
Django
Maxemp, 2017-09-02 18:52:23

Links overlap each other. How to solve it?

They are layered like this: 127.0.0.1:8000/post/6/post/5/post/4/post/3/post/2/...
How can I fix this?
I don't know what code to send, so I'll send everything I doubt.

urlpatterns = [
    url(r'^$', views.index, name="index"),
    url(r'post/(?P<index>[0-9]+)/$', views.post),
    url(r'login/$', views.login),
    url(r'signup/$', views.signup),
    url(r'signup_user/$', views.signup_user, name="signup_user"),
    url(r'check_user_name/$', views.check_user_name, name="check_user_name")
]

def post(request,index):
    try:
        test = Post.objects.get(id=index)
        previous_id = test.id - 1
        next_id = test.id + 1
        context = {
            "test": test,
            "previous_id": previous_id,
            "next_id": next_id,
            "max_id": len(Post.objects.all())
        }
        return render(request, "post.html", context)
    except Post.DoesNotExist:
        return render(request, "error_page.html")

{% extends "index.html" %}
{% load bootstrap3 %}
{% block bootstrap3_content %}

    <nav class="navbar navbar-default navbar-fixed-top" style="...">
        <div class="container">
            <div class="navbar-header">
                <span>
                    <a class="navbar-brand"><i class="fa fa-newspaper-o "></i>RSS News</a>
                </span>
            </div>
            <div class="navbar-right">
                <div class="navbar-text"><a class="btn btn-default btn-xs" href="/signup">signup</a> </div>
                <div class="navbar-text"><a class="btn btn-default btn-xs"href="/login">Log in</a></div>
            </div>
        </div>
    </nav>
        <div class="container" style="margin-top: 100px;">
            <div class="row">
                <div class="col-xs-12 text-left">
                    <h1>{{ test.title }}</h1>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12 text-left">
                    <div class="btn-group">
                        <a class="btn btn-sm btn-default" href="post/{{ previous_id }}" ><i class="fa fa-arrow-left"></i> Previous post</a> 
                        <a class="btn btn-sm btn-default" href="post/{{ next_id }}"> Next post <i class="fa fa-arrow-right"></i></a>
                    </div>
                </div>
            </div>
        </div>
{% endblock %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Astrohas, 2017-09-02
@Maxemp

"post/{{ previous_id }}"
replaced by
"/post/{{ previous_id }}"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question