Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
A simple Django application to easily use AJAX views with JavaScript.
django
>= 3.2python
>= 3.9Install the package via Pip:
pip install ajax-views
Add it to your INSTALLED_APPS
list:
INSTALLED_APPS = (
# ...
"ajax_views",
# ...
)
Add ajax_views.urls
to your URLconf:
from django.urls import include, path
urlpatterns = [
path("ajax/", include("ajax_views.urls")),
]
Use this decorator to register your views (Function-Based or Class-Based).
from ajax_views.decorators import ajax_view
@ajax_view("myapp.form")
def form_view(request):
...
@ajax_view("myapp.form_cbv")
class AjaxFormView(FormView):
...
NOTE: The specified name has to be unique.
You can combine ajax_view
with other decorators:
@csrf_exempt
@require_POST
@ajax_view("myapp.contact_form")
def csrf_exempt_view(request):
# ...
Template tag to output registered URLs as JSON.
{% load ajax_views %}
<script>
window.ajax_views = {% ajax_views_json %};
</script>
Now you can use the declared object to refer to the corresponding urls like this:
$.ajax({
url: window.ajax_views.myapp.form,
...
});
This tag is used to add AJAX URLs in the template files:
{% load ajax_views %}
<form action="{% ajax_url 'myapp.form' %}" method="post">
...
</form>
You can have multiple names for the same view:
from ajax_views.decorators import ajax_view
@ajax_view(["myapp.form", "myapp.fallback"])
def example_view(request):
...
Enable Jinja2 extension
TEMPLATES = [
{
"BACKEND": "django.template.backends.jinja2.Jinja2",
"OPTIONS": {
"extensions": [
# ...
"ajax_views.templatetags.ajax_views.AjaxViewsExtension",
]
}
}
]
NOTE: If you are using django-jinja, you don't need to do this.
The usage is similar to Django, except that ajax_url
is a global function:
<form action="{{ ajax_url('myapp.form') }}" method="post">
...
</form>
After cloning the Git repository, you should install this in a virtualenv and set up for development:
virtualenv .venv
source .venv/bin/activate
pip install -r ./requirements.txt
pre-commit install
FAQs
A simple Django application to easily use AJAX views with JavaScript.
We found that ajax-views demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.