后,我正在改变较早涉及到一些地理位置(失败),并在恢复以前的看法的一些看法,我收到此错误:Django的错误更改/还原浏览
TemplateSyntaxError at /report/all/
Caught NoReverseMatch while rendering: Reverse for 'profiles_profile_detail' with arguments '('',)' and keyword arguments '{}' not found.
什么奇怪的是,我修改和恢复的视图与此视图或模板无关。 urls.py文件根本没有被触及。应用程序中的所有其他页面都正常显示。我无法弄清楚问题可能是什么。
查看:
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))
形式(改变,但恢复;似乎运作):
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',)
模板:
{% 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 %}
错误就要到了就行了:
{% for story in stories %}
如果有人能提供为什么会这样的想法,那将是十分赞赏。同样,url没有改变,这似乎是造成这个错误的主要原因。
显示你的urls.py文件请......错误是在这条线{%URL profiles_profile_detail user.username%} –
URL模式=模式( '', URL(R '^所有/' 'stentorian.report.views.all_stories',名字= '全部'), URL(R '^细节/(ΔP \ d *)$', 'stentorian.report.views.story_detail',名字=”明细 '), URL(R' ^报告/ $ ' 'stentorian.report.views.submit_story',名字= 'write_story'), URL(R' ^细节/(ΔP \ d *)/编辑/ $”,‘stentorian.report.views.edit_story’,名字=‘edit_story’)道歉的代码在格式化,不能从Django的配置文件的应用程序弄清楚如何这样做IM的意见 –
和:URL模式= ('', url(r'^ create/$',views.create_profile,name ='profiles_create_profile'), url(r'^ edit/$', views.edit_profile, name ='profiles_edit_profile') , URL(R '^(θP \ w +)/ $', views.profile_detail, 名= 'profiles_profile_detail'), URL(R '^ $', views.profile_list, 名='profiles_profile_list '), ) –