簡體   English   中英

繼續收到服務器錯誤 - 500

[英]Keep getting Server Error - 500

每當我在我的網站上請求博客帖子時,我都會收到服務器錯誤500.我過去3天一直在嘗試調試它,但我無法弄清楚發生了什么。 以下是博客詳細信息的views.py:

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)

這是post.html模板:

{% 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是包含博客文章的模型。 我無法找到原因,當我請求博客頁面時,它會拋出錯誤。 有誰知道為什么?

我弄清楚發生了什么。 在@Tnerual的評論之后,我檢查了我的urls.py並且意識到request_post沒有被定義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM