如何修复NoReverseMatch?如果你没有获得授权就可以

时间:2017-06-16 08:02:33

标签: django view django-views url-routing

  

如果您未获得授权,那么一切都会正常工作   你授权,例如,adeline,我会发出这个错误   不知道发生了什么!

NoReverseMatch at / series / Colony / Season_1 / Episode_1 /

Reverse for 'post_of_serie' with no arguments not found. 1 pattern(s) tried: ['series/(?P<serial_slug>[\\w-]+)/(?P<season_slug>[\\w-]+)/(?P<series_slug>[\\w-]+)/$']

main urls.py

from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    url(r'^admin/', admin.site.urls),

    url(r'^series/', include("serials.urls", namespace='series')),
    url(r'^', include("serials.urls", namespace='homeview')),



]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

第二个urls.py到app(系列)

from django.conf.urls import include, url
from .views import homeview, post_of_serial, post_of_season, post_of_serie, validate_email, mark_and_unmark_this_episode

urlpatterns = [
   url(r'^$', homeview, name='homeview'),
   url(r'^subscribe/$', validate_email, name='subscribe'),   # /series/
   url(r'^mark_or_unmark_this_episode/$', mark_and_unmark_this_episode, name="mark_and_unmark_this_episode"),
   url(r'^(?P<serial_slug>[\w-]+)/$', post_of_serial, name='post_of_serial'),  # /series/Prison_Break/
   url(r'^(?P<serial_slug>[\w-]+)/(?P<season_slug>[\w-]+)/$', post_of_season, name='post_of_season'),  # /series/Prison_Break/season_5/
   url(r'^(?P<serial_slug>[\w-]+)/(?P<season_slug>[\w-]+)/(?P<series_slug>[\w-]+)/$', post_of_serie, name='post_of_serie'),  # /series/Prison_Break/season_5/2/  
]

错误ERROR

这是view.py

的一部分
def post_of_serie(request, serial_slug=None, season_slug=None, series_slug=None):
    serie                           = get_object_or_404(Series, serial_of_this_series__slug=serial_slug, season_of_this_series__slug=season_slug, slug=series_slug)
    #print(serie)
    title                           = serie.serial_of_this_series.rus_name_of_seriall
    full_path                       = All_Images_Of_The_Series.objects.filter(to_series__serial_of_this_series__slug=serial_slug, to_series__season_of_this_series__slug=season_slug, to_series__slug=series_slug, is_poster=True)

    context = {"serie":serie, "full_path":full_path, "title":title,}
    try:
        userr                       = request.user          
        check_button                = watched_series.objects.filter(user=request.user, watched_serial__slug=serial_slug, watched_serie__season_of_this_series__slug=season_slug, watched_serie__slug=series_slug )
        context["check_button"]     = check_button
        context["userr"]            = userr
    except:
        pass


    return render(request, 'series.html', context)

如果在views.py中删除somethig没有任何改变!!!

主要HTML

{% load staticfiles %}

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
        <title>{{ title }}</title>

        <!-- Bootstrap -->
        <link href="{% static "css/bootstrap.min.css"%}" rel="stylesheet">
        <link href="{% static "css/footer.css"%}" rel="stylesheet">
        <link href="{% static "css/main.css"%}" rel="stylesheet">
        {% block styles %}{% endblock styles %}


    </head>
    <body>
        <a href="{{ advertise_for_header.link_for_advertise }}"><div class="advertises" ></div></a>
        <div class="wrapper">
            <div class="wrapper-content">
            {% include "navbar.html" %}
            {% block content %}
            {% endblock content %}
            </div>
            {% include "footer.html" %}
        </div>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
        <script src="{% static "js/bootstrap.min.js"%}"></script>
        <script src="{% static "js/smooth-scroll.js"%}"></script>
        <script src="{% static "js/script.js" %}"></script>

    </body>
</html>

series.html哪里出错了!

{% extends "base.html" %}
{% load staticfiles %}

{% block content %}
    <div class="container">
        <div class="row">
            <div class="col-sm-8 her">
                <span class="links" >
                    <a class="a-link" href="{{ serie.serial_of_this_series.get_absolute_url }}">{{ serie.serial_of_this_series.rus_name_of_seriall }} <img src="{% static "img/breadcrumbs-arrow.png" %}" class="arrow"  > </a>

                    <a class="a-link" href="{{ serie.season_of_this_series.get_absolute_url }}">{{ serie.season_of_this_series.name_of_the_season }}<img src="{% static "img/breadcrumbs-arrow.png" %}" class="arrow"  ></a>

                    <a class="a-link" href="{{ serie.get_absolute_url }}">{{ serie.rus_name }}<img src="{% static "img/breadcrumbs-arrow.png" %}" class="arrow"  ></a>
                </span>

                <div class="title-block" >
                    <h3 class="seria-header">
                        <img src="{{ serie.serial_of_this_series.preview_of_serial.url }}" class="thumb">
                        <span class="titles" >
                            <div class="title-ru">{{ serie.rus_name }}</div>
                            <div class="title-en">{{ serie.eng_name }}</div>
                        </span>
                    </h3>
                    {% if user.is_authenticated %}
                        <form class="watch_button" method="POST" action="{% url 'series:post_of_serie' %}" > {% csrf_token %}
                            <div class="buttons" >
                                <div class="second_section_of_buttons" >
                                    {% if check_button %}
                                        <div class="isawthat-btn checcked" title="Серия просмотрена. Убрать пометку?" ><img src="{% static "img/white-eye-icon.png" %}" class="iccon"/><span class="text_button" >Серия просмотрена</span></div>
                                    {% else %}
                                        <div class="isawthat-btn" title="Пометить серию как просмотренную" ><img src="{% static "img/pink-eye-icon.png" %}" class="iccon"/><span class="text_button" >Серия Не просмотрена</span></div>
                                </div>
                                {% endif %}
                            </div>
                            <p class="user hidden" >{{ userr }}</p>
                            <p class="watched_serial hidden" >{{ serie.serial_of_this_series }}</p>
                            <p class="watched_serie hidden" >{{ serie }}</p>
                            <p class="minutes_of_series hidden" >{{ serie }}</p>
                            <p class="serial_slug hidden" > {{ serie.serial_of_this_series.slug }} </p>
                            <p class="season_slug hidden" > {{ serie.season_of_this_series.slug }} </p>
                            <p class="series_slug hidden" > {{ serie.slug }} </p>
                        </form>
                    {% endif %}
                </div>
            </div>

            <div class="col-sm-3">

            </div>
        </div>

    </div>

{% endblock content %}

1 个答案:

答案 0 :(得分:0)

<form class="watch_button" method="POST" action="{% url 'series:post_of_serie' %}" >

这是您遇到错误行的行,请参阅,此表单仅针对登录用户显示,并且您没有像def post_of_serie(request):

这样的视图

尝试以url的形式传递slu,然后问题就解决了