url没有打开下一页 - django / python

时间:2015-03-17 15:50:51

标签: python html django django-templates django-views

当我尝试选择一个我输入的按钮时,我希望它会将我带到“completed_event”网址。但是,它只显示“下一个URL”,它是它已经在的当前页面。换句话说,它会刷新页面,但不会打开我设置的下一个URL。

有人可以帮我重定向吗?

谢谢!

urls.py:

url(r'^event/completed/(?P<calendar_slug>[-\w]+)/(?P<event_id>\d+)/$',
    'schedule.views.completed_event',
    name='completed_event'),

views.py:

def completed_event(request, calendar_slug, event_id=None, next=None, form_class=EventForm):
    instance = None
    if event_id is not None:
        instance = get_object_or_404(Event, id=event_id)

    calendar = get_object_or_404(Calendar, slug=calendar_slug)

    next = get_next_url(request, next)
    context = {
        'next': next,
        'calendar': calendar,
    }
    return render(request, 'schedule/completed_event.html', context)

html文件:

{% if user.is_staff %}
    <a href="#" onclick="openURL('{{completed_event}}?next={{here}}', event);">
        <img border="0" src="{% static "schedule/img/completed.png" %}" alt="{% trans "Event Completed" %}">
    </a>
{% endif %}

1 个答案:

答案 0 :(得分:0)

您可以在{{}}之间使用上下文变量,并且没有名为completed_event的上下文变量。你真正想要的是命名URL的反向解析。而不是

<a href="#" onclick="openURL('{{completed_event}}?next={{here}}', event);">

<a href="#" onclick="openURL('{% url 'completed_event' %}?next={{ next }}', event);">

我还将here更改为next,因为它看起来像是一个错字;你没有名为here的上下文变量。