Skip to main content

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!".

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.2.tar.gz.

File metadata

File hashes

Hashes for canonicalwebteam.views-from-yaml-0.1.2.tar.gz
Algorithm Hash digest
SHA256 30b553af8996df3a983ebedc2a7c9e5bfc6f6a757db624450415b8c4bd4ca168
MD5 8d5c5b82aa990e6e779e0c3cd18930bb
BLAKE2b-256 69ca597eeff9e7d5d1b24814923f314763b958d37ccddc0dad2ed57a6423b598

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page