更改/恢复视图后出现Django错误

更改/恢复视图后出现Django错误,django,django-views,Django,Django Views,我之前更改了一些与失败的地理位置相关的视图,在恢复以前的视图时,我收到以下错误: TemplateSyntaxError at /report/all/ Caught NoReverseMatch while rendering: Reverse for 'profiles_profile_detail' with arguments '('',)' and keyword arguments '{}' not found. <div class="accordion" id="sto

我之前更改了一些与失败的地理位置相关的视图,在恢复以前的视图时,我收到以下错误:

TemplateSyntaxError at /report/all/
Caught NoReverseMatch while rendering: Reverse for 'profiles_profile_detail' with arguments '('',)' and keyword arguments '{}' not found.
 <div class="accordion" id="story_accordion">
        {% for story in stories %}
            <div class="accordion-group">
                <div class="accordion-heading">
                    <a class="accordion-toggle story-header" data-toggle="collapse" data-parent="#story_accordion" href="#story_{{ story.id }}">
                         {{ story.title }} - {{ story.author.username }} - {{ story.date }}
                    </a>
                </div>
                <div id="story_{{ story.id }}" class="accordion-body collapse{% if forloop.counter0 == 0 %} in{% endif %}">
                    <div class="accordion-inner">
                        <!-- <h2><a href="{% url detail story.id %}">{{story.title}}</a></h2>-->
                        <span><a href="{% url profiles_profile_detail story.author %}">{{story.author}}</a> </span><br>

                        <span>{{story.topic}}</span><br>
                        <span>{{story.zip_code}}</span><br>

                        <span>{{story.date}}</span><br>

                        <p>{{story.copy}}</p>
                    </div>
                </div>
            </div>

            <br>

        {% endfor %}
        </div>

    </div>
</div>

{% endblock content %}
奇怪的是,我修改和恢复的视图与此视图或模板无关。根本没有触及url.py文件。应用程序中的所有其他页面均正常显示。我想不出可能是什么问题

 <div class="accordion" id="story_accordion">
        {% for story in stories %}
            <div class="accordion-group">
                <div class="accordion-heading">
                    <a class="accordion-toggle story-header" data-toggle="collapse" data-parent="#story_accordion" href="#story_{{ story.id }}">
                         {{ story.title }} - {{ story.author.username }} - {{ story.date }}
                    </a>
                </div>
                <div id="story_{{ story.id }}" class="accordion-body collapse{% if forloop.counter0 == 0 %} in{% endif %}">
                    <div class="accordion-inner">
                        <!-- <h2><a href="{% url detail story.id %}">{{story.title}}</a></h2>-->
                        <span><a href="{% url profiles_profile_detail story.author %}">{{story.author}}</a> </span><br>

                        <span>{{story.topic}}</span><br>
                        <span>{{story.zip_code}}</span><br>

                        <span>{{story.date}}</span><br>

                        <p>{{story.copy}}</p>
                    </div>
                </div>
            </div>

            <br>

        {% endfor %}
        </div>

    </div>
</div>

{% endblock content %}
观点:

from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.template import RequestContext
from django.core.urlresolvers import reverse
from myapp.report.models import Story, UserProfile
from myapp.report.forms import ProfileForm, StoryForm
from django.contrib.auth.decorators import login_required
from django.contrib.gis.utils import GeoIP

def all_stories(request):
    if not request.user.is_authenticated():
        return redirect("django.contrib.auth.views.login")
    all_stories = Story.objects.all().order_by("-date")

    return render_to_response("report/storyline.html",
                                {'stories': all_stories},
                                context_instance=RequestContext(request))

def story_detail(request, story_id):
    story = get_object_or_404(Story, id=story_id)
    return render_to_response('report/detail.html',
                            {'story': story},
                                context_instance=RequestContext(request))

@login_required
def submit_story(request):
    if request.method =="POST":
        story_form = StoryForm(request.POST, request.FILES)
        if story_form.is_valid():
            new_story = story_form.save(commit=False)
            new_story.author = request.user
            new_story.save()
            return HttpResponseRedirect("/report/all/")
    else: # GET request
        story_form = StoryForm()
    return render_to_response("report/report.html", {'form': story_form}, context_instance=RequestContext(request))
 <div class="accordion" id="story_accordion">
        {% for story in stories %}
            <div class="accordion-group">
                <div class="accordion-heading">
                    <a class="accordion-toggle story-header" data-toggle="collapse" data-parent="#story_accordion" href="#story_{{ story.id }}">
                         {{ story.title }} - {{ story.author.username }} - {{ story.date }}
                    </a>
                </div>
                <div id="story_{{ story.id }}" class="accordion-body collapse{% if forloop.counter0 == 0 %} in{% endif %}">
                    <div class="accordion-inner">
                        <!-- <h2><a href="{% url detail story.id %}">{{story.title}}</a></h2>-->
                        <span><a href="{% url profiles_profile_detail story.author %}">{{story.author}}</a> </span><br>

                        <span>{{story.topic}}</span><br>
                        <span>{{story.zip_code}}</span><br>

                        <span>{{story.date}}</span><br>

                        <p>{{story.copy}}</p>
                    </div>
                </div>
            </div>

            <br>

        {% endfor %}
        </div>

    </div>
</div>

{% endblock content %}
形式改变了,但恢复了;似乎正在工作:

from django import forms
from stentorian.report.models import UserProfile, Story
from django.contrib.gis.utils import GeoIP

class ProfileForm(forms.ModelForm):
    class Meta:
        model = UserProfile

class StoryForm(forms.ModelForm):
    class Meta:
        model = Story
        exclude = ('author',)
 <div class="accordion" id="story_accordion">
        {% for story in stories %}
            <div class="accordion-group">
                <div class="accordion-heading">
                    <a class="accordion-toggle story-header" data-toggle="collapse" data-parent="#story_accordion" href="#story_{{ story.id }}">
                         {{ story.title }} - {{ story.author.username }} - {{ story.date }}
                    </a>
                </div>
                <div id="story_{{ story.id }}" class="accordion-body collapse{% if forloop.counter0 == 0 %} in{% endif %}">
                    <div class="accordion-inner">
                        <!-- <h2><a href="{% url detail story.id %}">{{story.title}}</a></h2>-->
                        <span><a href="{% url profiles_profile_detail story.author %}">{{story.author}}</a> </span><br>

                        <span>{{story.topic}}</span><br>
                        <span>{{story.zip_code}}</span><br>

                        <span>{{story.date}}</span><br>

                        <p>{{story.copy}}</p>
                    </div>
                </div>
            </div>

            <br>

        {% endfor %}
        </div>

    </div>
</div>

{% endblock content %}
模板:

{% extends 'base.html' %}

{% block page_title %}Stentorian{% endblock %}
{% block headline %}Stentorian Storyline{% endblock %}

{% block content %}

    <div class="row">
    <div class="span12">

        <h2>Welcome <a href="{% url profiles_profile_detail user.username %}">{{ user.username }}</a></h2>
 <div class="accordion" id="story_accordion">
        {% for story in stories %}
            <div class="accordion-group">
                <div class="accordion-heading">
                    <a class="accordion-toggle story-header" data-toggle="collapse" data-parent="#story_accordion" href="#story_{{ story.id }}">
                         {{ story.title }} - {{ story.author.username }} - {{ story.date }}
                    </a>
                </div>
                <div id="story_{{ story.id }}" class="accordion-body collapse{% if forloop.counter0 == 0 %} in{% endif %}">
                    <div class="accordion-inner">
                        <!-- <h2><a href="{% url detail story.id %}">{{story.title}}</a></h2>-->
                        <span><a href="{% url profiles_profile_detail story.author %}">{{story.author}}</a> </span><br>

                        <span>{{story.topic}}</span><br>
                        <span>{{story.zip_code}}</span><br>

                        <span>{{story.date}}</span><br>

                        <p>{{story.copy}}</p>
                    </div>
                </div>
            </div>

            <br>

        {% endfor %}
        </div>

    </div>
</div>

{% endblock content %}

如果有人能提供这种情况发生的原因,我们将不胜感激。同样,url没有更改,这似乎是导致此错误的主要原因。

似乎您没有获取user.username

 <div class="accordion" id="story_accordion">
        {% for story in stories %}
            <div class="accordion-group">
                <div class="accordion-heading">
                    <a class="accordion-toggle story-header" data-toggle="collapse" data-parent="#story_accordion" href="#story_{{ story.id }}">
                         {{ story.title }} - {{ story.author.username }} - {{ story.date }}
                    </a>
                </div>
                <div id="story_{{ story.id }}" class="accordion-body collapse{% if forloop.counter0 == 0 %} in{% endif %}">
                    <div class="accordion-inner">
                        <!-- <h2><a href="{% url detail story.id %}">{{story.title}}</a></h2>-->
                        <span><a href="{% url profiles_profile_detail story.author %}">{{story.author}}</a> </span><br>

                        <span>{{story.topic}}</span><br>
                        <span>{{story.zip_code}}</span><br>

                        <span>{{story.date}}</span><br>

                        <p>{{story.copy}}</p>
                    </div>
                </div>
            </div>

            <br>

        {% endfor %}
        </div>

    </div>
</div>

{% endblock content %}
试试这个

 <div class="accordion" id="story_accordion">
        {% for story in stories %}
            <div class="accordion-group">
                <div class="accordion-heading">
                    <a class="accordion-toggle story-header" data-toggle="collapse" data-parent="#story_accordion" href="#story_{{ story.id }}">
                         {{ story.title }} - {{ story.author.username }} - {{ story.date }}
                    </a>
                </div>
                <div id="story_{{ story.id }}" class="accordion-body collapse{% if forloop.counter0 == 0 %} in{% endif %}">
                    <div class="accordion-inner">
                        <!-- <h2><a href="{% url detail story.id %}">{{story.title}}</a></h2>-->
                        <span><a href="{% url profiles_profile_detail story.author %}">{{story.author}}</a> </span><br>

                        <span>{{story.topic}}</span><br>
                        <span>{{story.zip_code}}</span><br>

                        <span>{{story.date}}</span><br>

                        <p>{{story.copy}}</p>
                    </div>
                </div>
            </div>

            <br>

        {% endfor %}
        </div>

    </div>
</div>

{% endblock content %}
 <h2>Welcome <a href="{% url profiles_profile_detail request.user.username %}">{{ request.user.username }}</a></h2>

显示您的URL.py文件请。。。。。。这一行有错误{%url profiles\u profile\u detail user.username%}urlpatterns=patterns,urlr'^all/,'stentorian.report.views.all.'u故事',name='all',urlr'^detail/?P\d*$,'stentorian.report.views.story\u detail',name='detail',urlr'^report/$,'stentorian.report.views.submit\u故事',name='write\u故事',urlr“^detail/?P\d*/edit/$”,“stentorian.report.views.edit_story”,name='edit_story'为没有在代码中格式化而道歉;无法理解如何在im评论中执行此操作。从django profiles应用程序:urlpatterns=patterns,urlr'^create/$',views.create\u profile,name='profiles\u create\u profile',urlr'^edit/$',views.edit\u profile,name='profiles\u edit\u profile',urlr'^?P\w+/$,views.profile\u detail,name='profiles\u profile\u detail',urlr'^$',views.profile\u list,name='profiles\u profile\u list',相同错误。非常奇怪,因为到目前为止,它一直在运行,没有出现任何问题,也没有被触动。请参阅本页。您是否在根URLConf中包含了/profiles/?从模板中删除整行也会导致相同的错误。删除该行后,在呈现时/report/all/catch NoReverseMatch处出现/report/all/TemplateSyntaxError:对于带有参数的“profiles\u profile\u detail”和“关键字参数”{}未找到反向--这太奇怪了。是的,我在URLConf中包含了配置文件。所有其他页面都显示得很好。