{"id":13814115,"url":"https://github.com/ierror/django-js-reverse","last_synced_at":"2025-05-15T13:08:44.461Z","repository":{"id":638731,"uuid":"8014056","full_name":"ierror/django-js-reverse","owner":"ierror","description":"Javascript url handling for Django that doesn't hurt.","archived":false,"fork":false,"pushed_at":"2023-08-30T09:29:15.000Z","size":296,"stargazers_count":541,"open_issues_count":5,"forks_count":99,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-05-09T14:09:16.269Z","etag":null,"topics":["django","python","urls"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ierror.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS"}},"created_at":"2013-02-04T19:06:20.000Z","updated_at":"2025-04-10T20:52:24.000Z","dependencies_parsed_at":"2024-01-06T10:28:41.592Z","dependency_job_id":null,"html_url":"https://github.com/ierror/django-js-reverse","commit_stats":{"total_commits":268,"total_committers":33,"mean_commits":8.121212121212121,"dds":"0.49626865671641796","last_synced_commit":"1c5bb6e91fa52a0930a094b82acbe825b79adb36"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ierror%2Fdjango-js-reverse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ierror%2Fdjango-js-reverse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ierror%2Fdjango-js-reverse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ierror%2Fdjango-js-reverse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ierror","download_url":"https://codeload.github.com/ierror/django-js-reverse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254346624,"owners_count":22055808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","python","urls"],"created_at":"2024-08-04T04:01:43.790Z","updated_at":"2025-05-15T13:08:39.453Z","avatar_url":"https://github.com/ierror.png","language":"Python","readme":"=================\nDjango JS Reverse\n=================\n\n.. image:: https://img.shields.io/pypi/v/django-js-reverse.svg\n   :target: https://pypi.python.org/pypi/django-js-reverse/\n\n.. image:: https://img.shields.io/travis/ierror/django-js-reverse/master.svg\n   :target: https://travis-ci.org/ierror/django-js-reverse\n\n.. image:: https://img.shields.io/coveralls/ierror/django-js-reverse/master.svg\n   :alt: Coverage Status\n   :target: https://coveralls.io/r/ierror/django-js-reverse?branch=master\n\n.. image:: https://img.shields.io/github/license/ierror/django-js-reverse.svg\n    :target: https://raw.githubusercontent.com/ierror/django-js-reverse/master/LICENSE\n\n.. image:: https://img.shields.io/pypi/wheel/django-js-reverse.svg\n\n\n**Javascript url handling for Django that doesn’t hurt.**\n\n|\n|\n\n=============================================================================================================\n📣 This package is now maintained by `Vinta Software https://github.com/vintasoftware/django-js-reverse` 📣\n=============================================================================================================\n\n|\n|\n\n\nOverview\n--------\n\nDjango JS Reverse is a small django app that makes url handling of\n`named urls \u003chttps://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-patterns\u003e`__ in javascript easy and non-annoying..\n\nFor example you can retrieve a named url:\n\nurls.py:\n\n::\n\n    url(r'^/betterliving/(?P\u003ccategory_slug\u003e[-\\w]+)/(?P\u003centry_pk\u003e\\d+)/$', 'get_house', name='betterliving_get_house'),\n\nin javascript like:\n\n::\n\n    Urls.betterlivingGetHouse('house', 12)\n\nResult:\n\n::\n\n    /betterliving/house/12/\n\n\nRequirements\n------------\n\n+----------------+------------------------------------------+\n| Python version | Django versions                          |\n+================+==========================================+\n| 3.7            | 2.2, 2.1, 2.0, 1.11, 1.10, 1.9, 1.8      |\n+----------------+------------------------------------------+\n| 3.6            | 2.2, 2.1, 2.0, 1.11, 1.10, 1.9, 1.8      |\n+----------------+------------------------------------------+\n| 3.5            | 2.2, 2.1, 2.0, 1.11, 1.10, 1.9, 1.8      |\n+----------------+------------------------------------------+\n| 3.4            | 2.0, 1.11, 1.10, 1.9, 1.8, 1.7, 1.6, 1.5 |\n+----------------+------------------------------------------+\n| 2.7            | 1.11, 1.10, 1.9, 1.8, 1.7, 1.6, 1.5      |\n+----------------+------------------------------------------+\n\n\nInstallation\n------------\n\nInstall using ``pip`` …\n\n::\n\n    pip install django-js-reverse\n\n… or clone the project from github.\n\n::\n\n    git clone https://github.com/ierror/django-js-reverse.git\n\nAdd ``'django_js_reverse'`` to your ``INSTALLED_APPS`` setting.\n\n::\n\n    INSTALLED_APPS = (\n        ...\n        'django_js_reverse',\n    )\n\n\nUsage with webpack\n------------------\n\nInstall using ``npm``\n\n::\n\n    npm install --save django-js-reverse\n\n\nInclude none-cached view …\n\n::\n\n    urlpatterns = patterns('',\n        url(r'^jsreverse.json$', 'django_js_reverse.views.urls_json', name='js_reverse'),\n    )\n\n… or a cached one that delivers the urls JSON\n\n::\n\n    from django_js_reverse import views\n    urlpatterns = patterns('',\n        url(r'^jsreverse.json$', cache_page(3600)(views.urls_json), name='js_reverse'),\n    )\n\nInclude JavaScript in your bundle:\n\n::\n\n    // utils/djangoReverse.mjs\n    import _ from 'lodash/fp';\n    import djangoJsReverse from 'django-js-reverse';\n\n    export default _.once(\n      async () =\u003e {\n        const res = await fetch('/jsreverse.json');\n        const data = await res.json();\n        return djangoJsReverse(data);\n      }\n    )\n\n::\n\n    // somePlace.mjs\n    import djangoReverse from './utils/djangoReverse';\n\n    (async () =\u003e {\n      const urls = await djangoReverse();\n      const url = urls.someViewName('some-arg');\n      ...\n    })();\n\n\nUsage as static file\n--------------------\n\nFirst generate static file by\n\n::\n\n    ./manage.py collectstatic_js_reverse\n\nIf you change some urls or add an app and want to update the reverse.js file,\nrun the command again.\n\nAfter this add the file to your template\n\n::\n\n    \u003cscript src=\"{% static 'django_js_reverse/js/reverse.js' %}\"\u003e\u003c/script\u003e\n\n\nUsage with views\n----------------\n\nInclude none-cached view …\n\n::\n\n    urlpatterns = patterns('',\n        url(r'^jsreverse/$', 'django_js_reverse.views.urls_js', name='js_reverse'),\n    )\n\n… or a cached one that delivers the urls javascript\n\n::\n\n    from django_js_reverse.views import urls_js\n    urlpatterns = patterns('',\n        url(r'^jsreverse/$', cache_page(3600)(urls_js), name='js_reverse'),\n    )\n\nInclude javascript in your template\n\n::\n\n    \u003cscript src=\"{% url js_reverse %}\" type=\"text/javascript\"\u003e\u003c/script\u003e\n\nor, if you are using Django \u003e 1.5\n\n::\n\n    \u003cscript src=\"{% url 'js_reverse' %}\" type=\"text/javascript\"\u003e\u003c/script\u003e\n\n\nUsage as template tag\n_____________________\n\nYou can place the js_reverse JavaScript inline into your templates,\nhowever use of inline JavaScript is not recommended, because it\nwill make it impossible to deploy a secure Content Security Policy.\nSee `django-csp \u003chttps://django-csp.readthedocs.io/\u003e`__\n\n::\n\n    {% load js_reverse %}\n\n    \u003cscript type=\"text/javascript\" charset=\"utf-8\"\u003e\n        {% js_reverse_inline %}\n    \u003c/script\u003e\n\n\nUse the urls in javascript\n--------------------------\n\nIf your url names are valid javascript identifiers ([$A-Z\\_][-Z\\_$]\\*)i\nyou can access them by the Dot notation:\n\n::\n\n    Urls.betterlivingGetHouse('house', 12)\n\nIf the named url contains invalid identifiers use the Square bracket\nnotation instead:\n\n::\n\n    Urls['betterliving-get-house']('house', 12)\n    Urls['namespace:betterliving-get-house']('house', 12)\n\nYou can also pass javascript objects to match keyword aguments like the\nexamples bellow:\n\n::\n\n    Urls['betterliving-get-house']({ category_slug: 'house', entry_pk: 12 })\n    Urls['namespace:betterliving-get-house']({ category_slug: 'house', entry_pk: 12 })\n\nOptions\n-------\n\nOptionally, you can overwrite the default javascript variable ‘Urls’ used\nto access the named urls by django setting\n\n::\n\n    JS_REVERSE_JS_VAR_NAME = 'Urls'\n\nOptionally, you can change the name of the global object the javascript variable\nused to access the named urls is attached to. Default is :code:`this`\n\n::\n\n    JS_REVERSE_JS_GLOBAL_OBJECT_NAME = 'window'\n\n\nOptionally, you can disable the minfication of the generated javascript file\nby django setting\n\n::\n\n    JS_REVERSE_JS_MINIFY = False\n\n\nBy default all namespaces are included\n\n::\n\n    JS_REVERSE_EXCLUDE_NAMESPACES = []\n\nTo exclude any namespaces from the generated javascript file, add them to the `JS_REVERSE_EXCLUDE_NAMESPACES` setting\n\n::\n\n    JS_REVERSE_EXCLUDE_NAMESPACES = ['admin', 'djdt', ...]\n\nIf you want to include only specific namespaces add them to the `JS_REVERSE_INCLUDE_ONLY_NAMESPACES` setting\ntips:\n* Use \"\" (empty string) for urls without namespace\n* Use \"foo\\0\" to include urls just from \"foo\" namaspace and not from any subnamespaces (e.g. \"foo:bar\")\n\n::\n\n    JS_REVERSE_INCLUDE_ONLY_NAMESPACES = ['poll', 'calendar', ...]\n\nIf you run your application under a subpath, the collectstatic_js_reverse needs to take care of this.\nDefine the prefix in your django settings:\n\n::\n\n   JS_REVERSE_SCRIPT_PREFIX = '/myprefix/'\n\nBy default collectstatic_js_reverse writes its output (reverse.js) to your project's STATIC_ROOT.\nYou can change the output path:\n\n::\n\n    JS_REVERSE_OUTPUT_PATH = 'some_path'\n\n\nRunning the test suite\n----------------------\n\n::\n\n    tox\n\nLicense\n-------\n\n`MIT \u003chttps://raw.github.com/ierror/django-js-reverse/master/LICENSE\u003e`__\n\n\nContact\n-------\n\n`@i_error \u003chttps://twitter.com/i_error\u003e`__\n\n--------------\n\nEnjoy!\n","funding_links":[],"categories":["Web frontend integration","Python","Web 前端集成"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fierror%2Fdjango-js-reverse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fierror%2Fdjango-js-reverse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fierror%2Fdjango-js-reverse/lists"}