Comments (6)
Oh but it was not non-directly-loadable URLs I was pushing. I had just guessing that hx-push-url might be the reason - I'm not sure if it was.
Please come back with more info then :)
I think there's a key difference with require_http_methods
- for wrong methods, there isn't anything sensible to return. But HTML fragments are sensible and very useful for debugging, scraping, etc.
from django-htmx.
Will do!
The decorator could configured to be disabled if DEBUG=True - also as an opt-in it is/would be just a safe-guard against wrong usage if one chooses to use it. Having it redirect could also be optional, making it more akin to require_http_methods
.
from django-htmx.
I don't think I would personally use this. Being able to load up a view that returns a fragment for htmx can be useful for debugging at least. And I can't think of a common way that users would accidentally hit such URL's, since they're only mentioned in hx-* attrs normally? I've never seen a JSON API that analogously detects you're visiting from a browser and redirects you.
Can you explain more of what lead you to think of this?
from django-htmx.
I've had some experiences with my browser showing the raw output from a HTMX request when for instance accessing a page again after the browser being closed. It might have something to do with wrong usage of hx-push-url. My reasoning was that if I could just block of that kind of direct access, I would minimise those kinds of weird "accidental behaviour".
The idea with the decorator is to mimic the django builtin require_http_methods
decorator(s), in that it limits/guards the view from being accessed in a way that is not intended.
I also thought of including a call to django.utils.log.log_response
(like in require_http_methods
), to log if the decorated views are "used incorrectly".
from django-htmx.
Indeed you shouldn't push URL's into the location history that the user cannot load directly. Such URL's may be loaded in many situations: when the browser restarts, or the internet goes offline and returns, or if the user hits refresh. Displaying "fake" not-directly-loadable URL's seems like an anti-pattern to me.
Because of this I do not see the utility of the decorator.
from django-htmx.
Oh but it was not non-directly-loadable URLs I was pushing. I had just guessing that hx-push-url might be the reason - I'm not sure if it was.
Those random encounters (which I'll have to see if I can replicate somehow) were reason for the decorator. But I think that it has more merit than just avoiding that case - in the same way as require_http_methods
marks correct usage of a view.
from django-htmx.
Related Issues (20)
- Add reselect http method HOT 1
- The hx-headers="{'X-CSRFToken': '{{ csrf_token }}'}" Not Working, Forbidden (CSRF token missing.): HOT 3
- Relative Path Shortcut HOT 3
- Load script via htmx and execute HOT 1
- variation on django_htmx_script - load error into target, instead of replacing whole page HOT 1
- HX-Reselect response header not implemeted HOT 1
- The middleware doesn't work properly in asgi mode HOT 2
- Support more than just "true" as value for boolean request headers HOT 2
- Template tag? HOT 1
- Redirect after login HOT 4
- example app doesn't run HOT 1
- Add support for hx-replace-url HOT 2
- hx-put, hx-delete HOT 1
- Detection of partial htmx request in the presence of hx-history HOT 7
- MyPy error with "show" argument to reswap: incompatible type "str" HOT 3
- Request: Add short description to the readme or documentation that explains why to use this package. HOT 1
- Multiple HX-Trigger Response Headers HOT 1
- Feature: Add a "render_htmx" function to eliminate boilerplate `if request.htmx: ...` in every view
- Update page "context" without a full page reload
- Ignore this HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-htmx.