python - NoReverseMatch in url in django app -
i have url , everythis should ok error.
this url:
url(r'^/(?p<genre>%s)$' % '|'.join([g.code g in genre.objects.all()]), eventlistview.as_view(), name='genre'),
here error message:
reverse 'genre' arguments '()' , keyword arguments '{u'genre': ''}' not found. 0 pattern(s) tried: []
in line of html code:
<a {% if genre == view.genre %} class="active" href="{% url 'events' %}" title="{% trans 'reset filter' %}"{% else %} href="{% url 'genre' genre=genre.code %}"{% endif %}>{{ genre.name }}</a>
my view:
class eventlistview(pagecontextmixin, listview): model = booking page_context_kwargs = {'selected': reverse_lazy('events')} template_name = 'events/event_list.html' def get_queryset(self): filter_ = {'eventlist': true} # , 'season__in': settings.events_seasons} self.rooms = settings.events_rooms self.genres = list(settings.events_genres) genre_names = dict([(g.evis_id, g.description_de) g in genre.objects.filter(evis_id__in=[g['evis_id'] g in self.genres])]) genre in self.genres: genre['name'] = genre_names.get(genre['evis_id'], genre['name']) if 'genre' in self.kwargs: self.genre = [g g in self.genres if g['url'] == self.kwargs['genre']][0] filter_['eventgenre__genre__evis_id'] = self.genre['evis_id'] elif 'room' in self.kwargs: self.room = [r r in self.rooms if r['url'] == self.kwargs['room']][0] filter_['venue_description'] = self.room['venue_description'] return self.model.objects.filter(**filter_)
html template:
<div id="eventlistcontainer"> {% if view.genres or view.rooms %} <input type="checkbox" id="filteropener" class="hidden-input" /> <div class="filterwrap"> <label for="filteropener" class="filterlabel" title="{% trans "toggle filter" %}">{% trans "filter" %}</label> {% if view.genre or view.room %} <span class="filtertag"> : <b>{% if view.genre %}{{ view.genre.name }}{% else %}{{ view.room.name }}{% endif %}</b> </span> <a class="filterreset" href="{% url 'events' %}" title="{% trans 'reset filter' %}"> <img src="{{ static_url }}images/icon_close.png" alt="{% trans 'reset filter' %}" /> </a> {% endif %} </div> <div class="eventfilter"> <div> <h2>{% trans "genre" %}</h2> <ul class="linklist list1"> {% genre in view.genres %} <li> <a {% if genre == view.genre %} class="active" href="{% url 'events' %}" title="{% trans 'reset filter' %}"{% else %} href="{% url 'genre' genre=genre.code %}"{% endif %}>{{ genre.name }}</a> </li> {% if forloop.counter == 4 %} </ul> <ul class="linklist list2"> {% endif %} {% endfor %} </ul> </div> <div> <h2>{% trans "concert venues" %}</h2> <ul class="linklist list3"> {% room in view.rooms %} <li> <a {% if room == view.room %} class="active" href="{% url 'events' %}" title="{% trans "reset filter" %}"{% else %} href="{% url "room" room=room.url %}"{% endif %}>{{ room.name }}</a> </li> {% if forloop.counter == 6 %} </ul> <ul class="linklist list4"> {% endif %} {% endfor %} </ul> </div> </div> {% endif %} {% object_list|sort_by_highlight_past events %} <ul class="eventlist{% if events.0.past %} past{% endif %}"> {% event in events %} {% ifchanged event.past %} {% if not forloop.first %} </ul> <h3>vergangene veranstaltungen</h3> <ul class="eventlist past"> {% endif %} {% endifchanged %} <li class="{{ event.status|default:"" }}{% if forloop.first , not event.past %} wide{% endif %}"> {% im in event.eventimage_set.all|slice:":1" %} <a href="{{ event.get_absolute_url }}" class="image"> {% if forloop.parentloop.first , not event.past %} <img src="{{ im.image.image.3.url }}" alt="{{ im.text }}" /> {% endif %} <img src="{{ im.image.image.2.url }}" alt="{{ im.text }}" /> </a> {% endfor %} <div class="textbox"> <a href="{{ event.get_absolute_url }}"> <p class="date">{{ event.start|fancy_date }}</p> <h2>{{ event.name }}</h2> <p class="location">{{ event.venue_description }}</p> </a> {% if event.description_short %} <p class="additional-info">{{ event.description_short }}</p> {% endif %} <a href="{{ event.get_absolute_url }}" class="button">{% trans "details" %}</a> {% if event.status %} <p class="status">{% trans event.status %}!</p> {% elif event.selling_status_code == "ef" %} <a href="{{ event.get_absolute_url }}" class="button">{{ event.selling_status_description }}</a> {% elif event|ticket_link %} <a href="{{ event|ticket_link }}" class="button">{% trans "tickets" %}</a> {% endif %} </div> </li> {% endfor %} </ul> {% endwith %} </div>
genres
events_genres = ( { 'url': 'orchestermusik', 'evis_id': '1', 'name': 'orchestermusik' }, { 'url': 'vokale-musik', 'evis_id': '2', 'name': 'vokale musik' },)
trying put genres in url options bad idea. apart else, query evaluated once, url accept genres had been created @ server startup.
instead, kind of thing check in view, get_object_or_404
; has same result, of returning 404 if genre doesn't exist.
however, in particular case error because value of genre.code
passing {% url %}
tag empty reason. without seeing rest of template or view, though, can't tell why.
Comments
Post a Comment