this post was submitted on 17 Mar 2025
7 points (100.0% liked)
Django
479 readers
1 users here now
Django Project
- Django Project, the web framework for perfectionists with deadlines
- Django Code of Conduct
- Django Documentation
- Django Blog/News
- Support Django
Django Community
- Discord
- Unofficial Django Discord
- Project forum
- StackOverflow
- #django IRC Channel
- Django Users mailing list
- Django Developers mailing list
- Jazzband, a community maintaining Python projects
- Django Commons, organization dedicated to supporting the community's efforts to maintain packages
- Djangonaut Space
Django Ecosystem
- Built With Django
- Django Packages
- Django.WTF
- djangosnippets
- Awesome Django
- Django News
- Django Videos on pyvideo
- Django TV
- Upgrade Django
Jobs
Learning/Docs
- Django Project tutorial
- Django Girls Tutorial
- DjangoBook
- Classy Class-Based Views
- Classy Django REST Framework
- Classy DB
Podcasts:
Related Fediverse communities
- #django on Mastodon
- c/Python on programming.dev
- c/PostgreSQL on programming.dev
Feeds
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
In django you will typically define the url pattern with
uuid
being a keyword path parameter, and in the view code you can useget_object_or_404(Model, uuid=kwargs['uuid'])
. This way the user will see a standard 404 page if they attempt to view a page with uuid that does not exist.Of course, if you use class based views, you can extend detail view based off uuid, and the base class with handle the 404 page for you, so there'll be no need for
get_object_or_404
. I am assuming you will want to use class based views for this so you can extract the common functionality into a base class or a mixin and reuse it in a number of views.EDIT: I may have misunderstood the question wrong originaly. It looks like you want to bypass authentication for a subset of urls (or views). Authentication is not required by default in django, you can add
LoginRequiredMixin
(or a decorator) to your view, so not including the mixin would be a way to bypass the login requirement. Do you want to share relevant parts of your code for better suited advice?thanks for the fast answer!i think you understood it correctly. i want a public page, but certain things should only be accessed when you created a session/uuid beforehand.
class based views sound interesting. will probably use this. thanks again.
i have to think about, if i can tolerate the uuid being a query parameter of the url... somehow i like the uuid being part of the url better.
never the less. thanks a lot!
yeah it should definitely be part a of the url. It will be if you define a parametrized url. More details in the documentation https://docs.djangoproject.com/en/5.1/topics/http/urls/#url-dispatcher