Name | ajax-views JSON |
Version |
0.8.1
JSON |
| download |
home_page | None |
Summary | A simple Django application to easily use AJAX views with JavaScript. |
upload_time | 2024-12-16 17:53:07 |
maintainer | Mihail Mishakin |
docs_url | None |
author | Mihail Mishakin |
requires_python | <4.0,>=3.9 |
license | MIT |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# ajax-views
A simple Django application to easily use AJAX views with JavaScript.
[](https://pypi.org/project/ajax-views/)
[](https://github.com/dldevinc/ajax-views)
[](https://pypi.org/project/ajax-views/)
## Compatibility
- `django` >= 3.2
- `python` >= 3.9
## Features
- Ability to expose your AJAX URLs to JavaScript
- Supported Function-Based and Class-Based Views
- One URL pattern ~~to rule them all~~ for all AJAX views
- Jinja2 support
## Installation
Install the package via Pip:
```
pip install ajax-views
```
Add it to your `INSTALLED_APPS` list:
```python
INSTALLED_APPS = (
# ...
"ajax_views",
# ...
)
```
Add `ajax_views.urls` to your URLconf:
```python
from django.urls import include, path
urlpatterns = [
path("ajax/", include("ajax_views.urls")),
]
```
## Usage
#### @ajax_view("name")
Use this decorator to register your views (Function-Based or Class-Based).
```python
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:
```python
@csrf_exempt
@require_POST
@ajax_view("myapp.contact_form")
def csrf_exempt_view(request):
# ...
```
#### {% ajax_views_json %}
Template tag to output registered URLs as JSON.
```djangotemplate
{% 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:
```javascript
$.ajax({
url: window.ajax_views.myapp.form,
...
});
```
#### {% ajax_url 'name' %}
This tag is used to add AJAX URLs in the template files:
```djangotemplate
{% load ajax_views %}
<form action="{% ajax_url 'myapp.form' %}" method="post">
...
</form>
```
#### Multiple names
You can have multiple names for the same view:
```python
from ajax_views.decorators import ajax_view
@ajax_view(["myapp.form", "myapp.fallback"])
def example_view(request):
...
```
## Jinja2 support
Enable Jinja2 extension
```python
TEMPLATES = [
{
"BACKEND": "django.template.backends.jinja2.Jinja2",
"OPTIONS": {
"extensions": [
# ...
"ajax_views.templatetags.ajax_views.AjaxViewsExtension",
]
}
}
]
```
**NOTE**: If you are using [django-jinja](https://niwinz.github.io/django-jinja/latest/), you don't need to do this.
The usage is similar to Django, except that `ajax_url` is a global function:
```jinja2
<form action="{{ ajax_url('myapp.form') }}" method="post">
...
</form>
```
## Development and Testing
After cloning the Git repository, you should install this
in a virtualenv and set up for development:
```shell script
virtualenv .venv
source .venv/bin/activate
pip install -r ./requirements.txt
pre-commit install
```
Raw data
{
"_id": null,
"home_page": null,
"name": "ajax-views",
"maintainer": "Mihail Mishakin",
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": "x896321475@gmail.com",
"keywords": null,
"author": "Mihail Mishakin",
"author_email": "x896321475@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ec/f9/57a9fde207dd981e55f9dc03946389bb3ef819b104abae235d631ff567c6/ajax_views-0.8.1.tar.gz",
"platform": null,
"description": "# ajax-views\n\nA simple Django application to easily use AJAX views with JavaScript.\n\n[](https://pypi.org/project/ajax-views/)\n[](https://github.com/dldevinc/ajax-views)\n[](https://pypi.org/project/ajax-views/)\n\n## Compatibility\n\n- `django` >= 3.2\n- `python` >= 3.9\n\n## Features\n\n- Ability to expose your AJAX URLs to JavaScript\n- Supported Function-Based and Class-Based Views\n- One URL pattern ~~to rule them all~~ for all AJAX views\n- Jinja2 support\n\n## Installation\n\nInstall the package via Pip:\n\n```\npip install ajax-views\n```\n\nAdd it to your `INSTALLED_APPS` list:\n\n```python\nINSTALLED_APPS = (\n # ...\n \"ajax_views\",\n # ...\n)\n```\n\nAdd `ajax_views.urls` to your URLconf:\n\n```python\nfrom django.urls import include, path\n\nurlpatterns = [\n path(\"ajax/\", include(\"ajax_views.urls\")),\n]\n```\n\n## Usage\n\n#### @ajax_view(\"name\")\n\nUse this decorator to register your views (Function-Based or Class-Based).\n\n```python\nfrom ajax_views.decorators import ajax_view\n\n@ajax_view(\"myapp.form\")\ndef form_view(request):\n ...\n\n@ajax_view(\"myapp.form_cbv\")\nclass AjaxFormView(FormView):\n ...\n```\n\n**NOTE**: The specified name has to be unique.\n\nYou can combine `ajax_view` with other decorators:\n\n```python\n@csrf_exempt\n@require_POST\n@ajax_view(\"myapp.contact_form\")\ndef csrf_exempt_view(request):\n # ...\n```\n\n#### {% ajax_views_json %}\n\nTemplate tag to output registered URLs as JSON.\n\n```djangotemplate\n{% load ajax_views %}\n\n<script>\n window.ajax_views = {% ajax_views_json %};\n</script>\n```\n\nNow you can use the declared object to refer to the corresponding urls like this:\n\n```javascript\n$.ajax({\n url: window.ajax_views.myapp.form,\n ...\n});\n```\n\n#### {% ajax_url 'name' %}\n\nThis tag is used to add AJAX URLs in the template files:\n\n```djangotemplate\n{% load ajax_views %}\n\n<form action=\"{% ajax_url 'myapp.form' %}\" method=\"post\">\n ...\n</form>\n```\n\n#### Multiple names\n\nYou can have multiple names for the same view:\n\n```python\nfrom ajax_views.decorators import ajax_view\n\n@ajax_view([\"myapp.form\", \"myapp.fallback\"])\ndef example_view(request):\n ...\n```\n\n## Jinja2 support\n\nEnable Jinja2 extension\n\n```python\nTEMPLATES = [\n {\n \"BACKEND\": \"django.template.backends.jinja2.Jinja2\",\n \"OPTIONS\": {\n \"extensions\": [\n # ...\n \"ajax_views.templatetags.ajax_views.AjaxViewsExtension\",\n ]\n }\n }\n]\n```\n\n**NOTE**: If you are using [django-jinja](https://niwinz.github.io/django-jinja/latest/), you don't need to do this.\n\nThe usage is similar to Django, except that `ajax_url` is a global function:\n\n```jinja2\n<form action=\"{{ ajax_url('myapp.form') }}\" method=\"post\">\n ...\n</form>\n```\n\n## Development and Testing\n\nAfter cloning the Git repository, you should install this\nin a virtualenv and set up for development:\n\n```shell script\nvirtualenv .venv\nsource .venv/bin/activate\npip install -r ./requirements.txt\npre-commit install\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A simple Django application to easily use AJAX views with JavaScript.",
"version": "0.8.1",
"project_urls": {
"repository": "https://github.com/dldevinc/ajax-views"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b86e3d04e875ff4cdf21954d7466d4901bb82875b51c8f59a4dbbfced627f07b",
"md5": "390f1d2be975ccf26122c01d836bd963",
"sha256": "9bc71e4538ca4f9e1b15a7679e2bd4066f40aac556a600e6436877c50bfcd9c7"
},
"downloads": -1,
"filename": "ajax_views-0.8.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "390f1d2be975ccf26122c01d836bd963",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 7412,
"upload_time": "2024-12-16T17:53:04",
"upload_time_iso_8601": "2024-12-16T17:53:04.798355Z",
"url": "https://files.pythonhosted.org/packages/b8/6e/3d04e875ff4cdf21954d7466d4901bb82875b51c8f59a4dbbfced627f07b/ajax_views-0.8.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ecf957a9fde207dd981e55f9dc03946389bb3ef819b104abae235d631ff567c6",
"md5": "f1281cb4e9fc5c8395bada67f7039976",
"sha256": "05cc0a6ff0f370ad6cd4aa473ce6342af626a9e9a70fb46432dd437c1e65b8f4"
},
"downloads": -1,
"filename": "ajax_views-0.8.1.tar.gz",
"has_sig": false,
"md5_digest": "f1281cb4e9fc5c8395bada67f7039976",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 6862,
"upload_time": "2024-12-16T17:53:07",
"upload_time_iso_8601": "2024-12-16T17:53:07.140708Z",
"url": "https://files.pythonhosted.org/packages/ec/f9/57a9fde207dd981e55f9dc03946389bb3ef819b104abae235d631ff567c6/ajax_views-0.8.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-16 17:53:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dldevinc",
"github_project": "ajax-views",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "ajax-views"
}