如何为特定用户生成唯一的URL [英] How can I generate an unique url for a specific user

查看:274
本文介绍了如何为特定用户生成唯一的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用flask来构建网络应用,并将数据存储在名为Orders的表中。

I’m using flask to build a web app and I store data in a table called Orders.

我希望买家能够访问一个模板,该模板将显示其订单数据,例如跟踪,状态等。我还想给他们一些操作,例如返回订单。

I want buyers to have access to a template that will display their order data, like tracking, status, etc. Also I want to give them some actions like the ability to return the order.

为了方便起见和用户体验,我不希望买家进行注册。我想通过电子邮件发送给他们一个链接,该链接将直接为他们提供访问其订单信息的权限。因此,我将为每个带有令牌的订单创建一条动态路线。我也不希望该令牌真的很明显,例如订单号或类似的东西,因为这样任何人都可以猜测一个URL并返回例如不是他们的订单。因此,它必须是唯一的,并且是一长串随机字符。我应该怎么做,这是好的方法还是不好的设计?

For convenience and user experience purposes, I don’t want buyers to register. I want to email them a link that will directly give them access to their order information. So I will create a dynamic route for each order with a token. I also don’t want that token to be really obvious, like order number or something similar, because then anyone can guess an url and return a order that’s not theirs for instance. So it must be unique and a long string of random characters. How should I do it and is this a good approach or bad design?

谢谢!

推荐答案

是的,您可以使用Variable从烧瓶中获取规则,您可以在url中放置如下路径:

Yes you can do it using Variable Rules from flask, you can put a path in url like this:

@app.route('/user/<path:dinamicPath>')
def show_subpath(dinamicPath):
   if dinamicPath == 'order':
      order = Order.get() #get your orderns from db or files
      return render_template('order.html', order=order)
   elif dinamicPath == 'otherStuff':
      ...
      return

因此,我将为每个带有令牌的订单创建一条动态路线。我也不希望该令牌真的很明显,例如订单数字或类似名称,您也可以使用UUID,变量规则也支持它,您可以查看此链接在此处输入链接描述

"So I will create a dynamic route for each order with a token. I also don’t want that token to be really obvious, like order number or something similar" you can use a UUID, its supported in Variable Rules too, you can look this link enter link description here

这篇关于如何为特定用户生成唯一的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆