【问题标题】:url not opening next page - django/pythonurl 没有打开下一页 - django/python
【发布时间】:2015-03-18 00:44:32
【问题描述】:

当我尝试选择我输入的按钮时,我希望它会将我带到“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 %}

【问题讨论】:

  • 如果在请求中传递了 url next 属性,是否要将用户重定向到该 url ?
  • 您不只是将链接用作链接有什么原因吗?

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


【解决方案1】:

您可以在{{}} 之间使用上下文变量,并且没有名为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 的上下文变量。

【讨论】:

    猜你喜欢
    • 2017-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    • 1970-01-01
    相关资源
    最近更新 更多