M
M
marataziat2017-01-22 13:52:09
Flask
marataziat, 2017-01-22 13:52:09

How to make slashes not considered slashes in flask?

My code:

from flask import Flask
import redis, names, random, validators
app = Flask(__name__)
#r = redis.StrictRedis(host='localhost', port=6379, db=0)
#print r.get('foo')

@app.route("/<UrlToSHort>")
def CreateShortLink(UrlToSHort):
  if validators.url(UrlToSHort) == True:
    ShortedLinkName = names.get_first_name() + str(random.randint(1,130))
    r = redis.StrictRedis(host='localhost', port=6379, db=0)
    r.set(ShortedLinkName, UrlToSHort)
    return r.get(ShortedLinkName)
  else:
    return "Your link is not !!!"

if __name__ == "__main__":
    app.run(debug=True)

How can I make it so that when I go to 127.0.0.1:5000/http://google.com I don't see a 404 error, but just pass the full google.com

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pcdesign, 2017-01-22
@marataziat

@app.route("/<path:UrlToSHort>")
You can try adding path:
flask.pocoo.org/snippets/76

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question