Python URL handling for Django (based on django-js-reverse)
Project description
django-py-reverse
Installation
pip install django_py_reverse
# or using poetry
poetry add django_py_reverse
Usage
from django_py_reverse import Urls
API_ENDPOINT = "https://example.com/api/v1"
data_urls = {
"urls": [
[
"account_confirm_email",
[["accounts/confirm_email/%(key)s/", ["key"]]],
],
["account_delete", [["accounts/delete/", []]]],
["account_password_reset", [["es/accounts/password/reset/", []]]],
[
"account_password_reset_token",
[
[
"accounts/password/reset/%(uidb36)s-%(token)s/",
["uidb36", "token"],
]
],
],
],
"prefix": "/",
}
urls = Urls(data=data_urls, url_prefix=API_ENDPOINT).factory()
print(urls['account_confirm_email'](key="123"))
print(urls['account_delete']())
print(urls['account_password_reset']())
print(urls['account_password_reset_token'](uidb36="123", token="456"))
# Output:
# https://example.com/api/v1/accounts/confirm_email/123/
# https://example.com/api/v1/accounts/delete/
# https://example.com/api/v1/es/accounts/password/reset/
# https://example.com/api/v1/accounts/password/reset/123-456/
Include JS Style
urls = Urls(data=data_urls, url_prefix=API_ENDPOINT, include_js_style=True).factory()
print(urls['accountConfirmEmail'](key="123"))
print(urls['accountDelete']())
print(urls['accountPasswordReset']())
print(urls['accountPasswordResetToken'](uidb36="123", token="456"))
# Output:
# https://example.com/api/v1/accounts/confirm_email/123/
# https://example.com/api/v1/accounts/delete/
# https://example.com/api/v1/es/accounts/password/reset/
# https://example.com/api/v1/accounts/password/reset/123-456/
You can get the urls from your current django & django-js-reverse project more info here
wget ${API_ENDPOINT}/jsreverse/json/ -O data/urls.json
Then on your python project
import json
from django_py_reverse import Urls
API_ENDPOINT = "https://example.com/api/v1"
with open("data/urls.json") as f:
data_urls = json.load(f)
urls = Urls(data=data_urls, url_prefix=API_ENDPOINT).factory()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_py_reverse-1.0.1.tar.gz.
File metadata
- Download URL: django_py_reverse-1.0.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.5 Linux/6.10.7-200.fc40.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89300d7948819f2cbe2e009c7f2cdebaa0dd57abdc2f1890f2fe25632d31a5a9
|
|
| MD5 |
970c25e68f770ca3f62bb8a58263d754
|
|
| BLAKE2b-256 |
90aa1cd0ff22e0ff66fe55bb8f7e1207cf4f7debce4ca54092fcadf1a1993715
|
File details
Details for the file django_py_reverse-1.0.1-py3-none-any.whl.
File metadata
- Download URL: django_py_reverse-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.5 Linux/6.10.7-200.fc40.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
561d8df8428354726306c39a90635d4760658b368add622845e2ef2b2d02629a
|
|
| MD5 |
b2e39bff34de6d3d95c34497faa830d9
|
|
| BLAKE2b-256 |
fa04d744a40ee5c886d85a10921f8de34c776616e45dfe09fa42cf11170c60b6
|