Is there a way, in Django, to define routes using Flask-style route syntax?
Question:
Setting aside any strongly-held feelings about Django vs Flask, I have a whole bunch of Flask-style routes I’d like to convert to Django. They look like your usual Flask routes:
'/foo/<spam>/<int:eggs>/'
This gets even more complex with converters in Flask like path
:
'/foo/<path:location>'
So I have all of these routes, and I’d rather not try to figure out regular expressions that approximate them in converting my views. I’m looking to just parse the Flask-style routes in Django. Is there a way to use Flask-style route patterns in Django?
Answers:
Have not personally used it, but this sounds exactly what you are asking about – django-fsu
:
Flask-Style URL Patterns for Django
I would though still try to stick to Django URL-routing style and avoid “transitional” solutions like this. You can also use django-fsu
temporarily to migrate, then cover all the endpoints with end-to-end and functional tests and, then, once you have the coverage, migrate to the Django native URL routing style.
Setting aside any strongly-held feelings about Django vs Flask, I have a whole bunch of Flask-style routes I’d like to convert to Django. They look like your usual Flask routes:
'/foo/<spam>/<int:eggs>/'
This gets even more complex with converters in Flask like path
:
'/foo/<path:location>'
So I have all of these routes, and I’d rather not try to figure out regular expressions that approximate them in converting my views. I’m looking to just parse the Flask-style routes in Django. Is there a way to use Flask-style route patterns in Django?
Have not personally used it, but this sounds exactly what you are asking about – django-fsu
:
Flask-Style URL Patterns for Django
I would though still try to stick to Django URL-routing style and avoid “transitional” solutions like this. You can also use django-fsu
temporarily to migrate, then cover all the endpoints with end-to-end and functional tests and, then, once you have the coverage, migrate to the Django native URL routing style.