Is it possible to make URL in Django to follow folder path like in GitHub, Dropbox
https://github.com/<username>/<path>/<path>/<file>
Currently, I am doing it like this
re_path(r'^.*', myview)
then using the split('/')
function in view
Is there is a batter way to do that?
The functionality of the website is that you can create a folder and inside that folder, you can either create another new folder or create a file.
Let’s say if you create a folder called python and create a file in this folder called list, then the URL must be like this
www.bla-bla.com/python/list/
And if you create a new folder in the python folder called “data type” and create a file “list” in “data type” folder then the URL must look like this
www.bla-bla.com/python/data-type/list/
Just to make URL more SEO friendly.
Thanks
2
Answers
I couldn’t completely understand what is your problem. When designing a web app you gotta create routes and then from inside of the functions to handle each route you render w/e html file you want. Example
reference – https://docs.djangoproject.com/en/2.2/intro/tutorial03/#targetText=A%20view%20is%20a%20%E2%80%9Ctype,page%20for%20a%20single%20entry.
that’s how it’s done in flask – https://hackersandslackers.com/the-art-of-building-flask-routes/#targetText=Flask%20contains%20a%20built%2Din,a%20function%20containing%20route%20logic.
If I understand your question correctly, the best way to do this is:
urls.py
views.py