简体   繁体   中英

Keep getting Server Error - 500

Every time I request a blog post on my website, I receive a server error 500. I have been trying to debug it for the past 3 days, and I have not been able to figure out what is going on. Here is the views.py for the blog detail:

def blog_detail():

    post = Post.objects.get(request_post)


    try:
        Next_Post_id = (post.id + 1)
        Next_Post = Post.objects.get(id=Next_Post_id)
        Next_Post = Next_Post.id
    except ObjectDoesNotExist:
        Next_Post = None

    # Previous Post
    try:
       Previous_Post_id = (post.id - 1)
       Previous_Post = Post.objects.get(id=Previous_Post_id)
       Previous_Post = Previous_Post.id
    except ObjectDoesNotExist:
        Previous_Post = None

    context = {'post': post, 'Next_Post': Next_Post, 'Previous_Post':  Previous_Post}
    return render(request, "BlogHome/pages/post.html", context)

and here is the post.html template:

{% extends "BlogHome/includes/WELL.html" %}

{% block content %}
<script>
document.title = "Pike Dzurny | {{post.title}}"
</script>
    <div class="container-fluid text-center">
        <center>
            <div class="well" id="WellPost">
                <div class="container-fluid">
                    <h2 align="center" id="TitleText">{{post.title}}</h2>
                    <h3 align="center" id="BodyText">{{ post.date|date:"m-d"}}</h3>


            <h3 align="left">{{ post.body|safe }}</h3>


                {% if post.id == 1 %}
                <ul class="pager">
                    <li class="previous disabled"><a href="/blog/{{ Previous_Post.id }}"><span
                            aria-hidden="true">&larr;</span> Older</a></li>
                    <li class="next "><a href="/blog/{{ Next_Post.id }}">Newer <span
                            aria-hidden="true">&rarr;</span></a></li>
                    <h1>hi 1</h1>
                </ul>

                {% if Next_Post is defined %}
                <ul class="pager">
                    <li class="previous disabled"><a href=""><span aria-hidden="true">&larr;</span> Older</a></li>
                    <li class="next"><a href="/blog/{{ Next_Post.id }}">Newer <span aria-hidden="true">&rarr;</span></a>
                    </li>
                </ul>
                <h1>2</h1>

                {% Previous_Post is defined %}
                <ul class="pager">
                    <li class="previous"><a href="/blog/{{ Previous_Post.id }}"><span aria-hidden="true">&larr;</span>
                        Older</a></li>
                    <li class="next disabled"><a href="">Newer <span aria-hidden="true">&rarr;</span></a></li>
                </ul>
                <h1>3</h1>

                {% else %}
                <ul class="pager">
                    <li class="previous disabled"><a href=""><span aria-hidden="true">&larr;</span> Older</a></li>
                    <li class="next disabled"><a href="">Newer <span aria-hidden="true">&rarr;</span></a></li>
                </ul>
                <h1>4</h1>
                {% endif %}


            </div>
            <div class="container-fluid">

            </div>
    </center>

</div>

{% endblock %}

Post is the model that contains the blog post. I have not been able to find the reasong why when I request a blog page it throws an error. Does anyone know why?

I figured out what happened. After @Tnerual's comment, I checked my urls.py and realized request_post wasn't defined.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM