Django URLs configurations Reader.
Reads all urls configurations (urls.py
) declared in all Django projects within a VSCODE workspace and copy to clipboard.
New in version 2.1
✨✨Introducing settings for the extension ✨✨
Models in the project are now automatically detected by the extension.
You can now switch between keyword and positional arguments in settings for your urls.
Built-in auth/django.contrib.auth
URL configurations can be included or not depending on settings using builtInAuth: true
Gives the option of copying the url as reverse, reverse_lazy or as a template tag to your clipboard.
Install from here.
Jump to:
• Usage.
• Settings.
• Custom Url configurations.
• Creating Custom URL configurations.
• Using ModelAdmin
urls.
• Multiple Django folders support.
Usage.
The extension adds a view on your side bar with an icon like a chain 🔗. Navigate to that view and click to open it and
activate the extension.
Give it a few moments to read all urls and populate the view. Once done it will populate the view with your URL configurations.
Each app will be a collapsable tree with its urls as the children. App names are in ALL CAPS. If an app has no app_name
it will be displayed in the following format PARENT_FOLDER\URLS.PY
.
A url may have children if it's arguments are defined.
If not the it's a single item.
Actions.
On hovering over a url name, there are three buttons (from left to right).
- Copy 'reverse' url.
- Copy 'reverse_lazy' url.
- Copy as a template tag.
All three copy to clipboard and can be pasted in your code, all you need to change is names of the arguments to match you namespace (The arguments are surrounded by '%' to make sure your editor or linter catches it to remind you to change it).
The three are copied using keyword arguments i.e. kwargs to switch to positional arguments i.e. args add urlWithKeywords: false
to settings.
Settings
The extension now has settings. They live inside .vscode/urlConfigs/settings.json
inside in your project. They are on a project by project basis. If you have two projects in one workspace, each project shall have it's own sets of settings.
Options for settings are explained below showing an example .vscode/urlConfigs/settings.json
file;
{
"adminUrls": true,
"autoLoadModels": true,
"registeredAppsOnly": false,
"builtInAuth": false,
"expandApps": "normal",
"urlWithKeywords": true
}
adminUrls
[Boolean]: true
to show admin site urls configurations and false
to not show.
autoLoadModels
[Boolean]: true
to automatically discover models and false
to use just .vscode/urlConfigs/models.json
(the traditional approach).
registeredAppsOnly
[Boolean]: Automatically detect models from registered apps only. Default is false
.
builtInAuth
[Boolean]: true
to show url configurations from the built-in authentication sytem i.e. django.contrib.auth.urls
or false
to not.
expandApps
[String]: Collapse or expand the Apps to show urls. Choices are 3; collapsed
, expanded
or normal
. normal is the default.
urlWithKeywords
[Boolean]: The reverse & reverse_lazy functions and url template tag use keywords arguments if true
and positional arguments if false
i.e. args or kwargs. The default is true.
expandApps
requires a window reload to show changes
Custom URL configurations.
Sometimes you need 3rd party apps in your project which may have URL configurations. These configurations can be described in a JSON file named in the format; 'app.conf.json
'. These files are saved in '.vscode/urlConfigs/
' folder in the root of your project to allow the extension to find them. They are combined with your project's configurations. To describe the URL configurations click here.
The extension comes pre-loaded with the AdminSite
, ModelAdmin
, django.contrib.auth
and UserAdmin
configurations.
To turn off AdminSite, ModelAdmin and UserAdmin, add adminUrls: false
to settings.
To turn on django.contrib.auth
URL configurations, add builtInAuth: true
to settings.
Creating custom configurations.
The JSON file, named in the format described in the previous section, contains a list/array of Whole app configurations. i.e. Your whole project, no matter home many apps/urls.py there are, would be added to one *.conf.json
file. Say there are three apps in your project, api
, store
, billing
, they can be described in one file or a separate file for each.
Custom configurations appear at the top and are collapsed by default.
Each app entry, in the array of apps, is an object with two properties:
appName
[String]: A string with the name of the app. (Note this is not the usual app_name
declared in the urls.py
. It will just appear as the title in our URl configurations view).
urls
[Array]: An array of url configurations objects for that app. If no URL configurations leave as an empty array []
. A url configuration object is in the following format:
reverseName
[String]: This is the actual reverse name. If the app has an app_name
and the name of the url is index
, enter this as app_name:index
. If no app_name
enter as index
.
arguments
[Array]: An array of a URL configuration parameters object. If there are no arguments leave this an empty array []
. These objects are in the format:
name
[String]: The name of the parameter as described in the urls.py
file.
argType
[String]: The type of the parameter. Options are either: string, slug, uuid, integer.
viewName
[String]: The name of the view that handles that URL.
hasArgs
[Boolean]: false
if arguments
/ entry 2 above is empty and vice versa.
To load changes click the reload button.
Example in a *.conf.json
file:
[
{
"appName": "example",
"urls": [
{
"reverseName": "url1",
"arguments": [
{
"name": "name",
"argType": "string"
},
{
"name": "name_2",
"argType": "slug"
}
],
"viewName": "views.example_1",
"hasArgs": true
},
{
"reverseName": "url2",
"arguments": [],
"viewName": "views.example_2",
"hasArgs": false
}
]
},
{
"appName": "example_app_2",
"urls": [
{
"reverseName": "url3",
"arguments": [],
"viewName": "views.example_3",
"hasArgs": false
}
]
}
]
Incase of incorrect configurations, the file is ignored.
Check out the admin configurations file🧐.
ModelAdmin
URLs.
Models in your project are AUTOMATICALLY detected by the extension. This option is enabled by default, to turn off add autoLoadModels: false
to settings. To add more models, third party models or others, add an object in .vscode/urlConfigs/models.json
with properties as app_labels (peak into apps.py
) and a list of model names.
To load changes click the reload button.
~~Changes to detect models automatically are in development.~~
Models can now be automatically detected.
{
"app_label": ["model1", "model2"],
"app_label_2": ["model3"]
}
*The extension detects models if you use the built-in django.contrib.admin
and have admin.py
or /admin/__init__.py
in your apps. Support for others coming soon :)
Multiple Projects in a workspace.
The extension now supports multiple projects in one workspace. Once you add a folder to the workspace, reload the window to view changes.
MISC
• Created by Muremwa.
• Copying to clipboard made possible by clipboardy.
• Released under the MIT License.