【问题标题】:Link to URL based on form input upon clicking submit单击提交时根据表单输入链接到 URL
【发布时间】:2014-06-13 00:21:38
【问题描述】:

我的目标是让用户输入一个日期以检索所选日期的预测数据。我的 URL 格式为 wwww.mywebsite.com/forecasts/region/{{date}}(我正在使用 Pyramid 的 URL 调度)。我希望用户能够以 YYYYMMDDHH 格式输入日期,并在单击提交时将用户带到该日期的 url。有没有办法在 HTML 中做到这一点?或者 Javascript 或服务器端 python 会是更好的选择吗?谢谢

【问题讨论】:

    标签: javascript python html


    【解决方案1】:

    您可以像这样在服务器端使用 python 轻松完成:

    @view_config(route_name='foo')
    def foo(request):
        #get date like something like this:
        if ('date' in request.params.keys()):
            userInputDate = request.params.get('date')
    
        #redirect the user to date specific view
        return HTTPFound(location=request.route_url('bar', date = userInputDate)
    
    @view_config(route_name='bar', renderer='bar.mak')
    def bar(request):
       #get that usergiven date
       date = request.matchdict['date']
       #do stuff
    

    酒吧的路线定义:

    config.add_route('bar','/bar/{date:\d+}')
    

    这会创建具有变化值的网址,例如日期。更多信息请点击此处:http://docs.pylonsproject.org/docs/pyramid/en/1.5-branch/narr/urldispatch.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-11
      • 2015-01-11
      • 1970-01-01
      • 2017-11-24
      • 2013-10-18
      • 2012-03-28
      相关资源
      最近更新 更多