A helper function for creating Django views from a YAML file of URL paths
Project description
A helper function for creating views from a YAML file of URL paths
==================================================================
Installation
------------
.. code:: bash
pip install canonicalwebteam.views-from-yaml
Usage
-----
E.g. create a YAML file:
.. code:: yaml
# url-settings.yaml
some/url/path: {"content": "Hello world!"}
another/path: {"content": "Different content"}
And edit your Django app's ``urls.py``\:
.. code:: python
# django_app/urls.py
from canonicalwebteam.views_from_yaml import load_views_from_file
def url_view(request, url_settings):
return HttpResponse(url_settings['content'])
urlpatterns = load_views_from_file(
yaml_filepath="url-settings.yaml",
view_callback=url_view
)
Now if you visit `http://your-django-site/some/url/path` you should see
"Hello world!".
==================================================================
Installation
------------
.. code:: bash
pip install canonicalwebteam.views-from-yaml
Usage
-----
E.g. create a YAML file:
.. code:: yaml
# url-settings.yaml
some/url/path: {"content": "Hello world!"}
another/path: {"content": "Different content"}
And edit your Django app's ``urls.py``\:
.. code:: python
# django_app/urls.py
from canonicalwebteam.views_from_yaml import load_views_from_file
def url_view(request, url_settings):
return HttpResponse(url_settings['content'])
urlpatterns = load_views_from_file(
yaml_filepath="url-settings.yaml",
view_callback=url_view
)
Now if you visit `http://your-django-site/some/url/path` you should see
"Hello world!".
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file canonicalwebteam.views-from-yaml-0.1.1.tar.gz
.
File metadata
- Download URL: canonicalwebteam.views-from-yaml-0.1.1.tar.gz
- Upload date:
- Size: 1.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d3760aaed3f1ffdd67aaeda7828f2a29765f09d9f8f7be1c67eb4884ac484a6 |
|
MD5 | 48a9025a9eaa32f5b5f37eef92aff8d9 |
|
BLAKE2b-256 | f5018f96c1b9c540735be169197fb8f5df39b5c979f34b6aeb2011d5deac7bdf |