Skip to main content
Glama

Django Styleguide MCP Server

by dmmeteo
urls.md•2.78 kB
## Urls We usually organize our urls the same way we organize our APIs - 1 url per API, meaning 1 url per action. A general rule of thumb is to split urls from different domains in their own `domain_patterns` list & include from `urlpatterns`. Here's an example with the APIs from above: ```python from django.urls import path, include from project.education.apis import ( CourseCreateApi, CourseUpdateApi, CourseListApi, CourseDetailApi, CourseSpecificActionApi, ) course_patterns = [ path('', CourseListApi.as_view(), name='list'), path('<int:course_id>/', CourseDetailApi.as_view(), name='detail'), path('create/', CourseCreateApi.as_view(), name='create'), path('<int:course_id>/update/', CourseUpdateApi.as_view(), name='update'), path( '<int:course_id>/specific-action/', CourseSpecificActionApi.as_view(), name='specific-action' ), ] urlpatterns = [ path('courses/', include((course_patterns, 'courses'))), ] ``` **Splitting urls like that can give you the extra flexibility to move separate domain patterns to separate modules**, especially for really big projects, where you'll often have merge conflicts in `urls.py`. Now, if you like to see the entire url tree structure, you can do just that, by not extracting specific variables for the urls that you include. Here's an example from our [Django Styleguide Example](https://github.com/HackSoftware/Django-Styleguide-Example/blob/master/styleguide_example/files/urls.py): ```python from django.urls import path, include from styleguide_example.files.apis import ( FileDirectUploadApi, FilePassThruUploadStartApi, FilePassThruUploadFinishApi, FilePassThruUploadLocalApi, ) urlpatterns = [ path( "upload/", include(([ path( "direct/", FileDirectUploadApi.as_view(), name="direct" ), path( "pass-thru/", include(([ path( "start/", FilePassThruUploadStartApi.as_view(), name="start" ), path( "finish/", FilePassThruUploadFinishApi.as_view(), name="finish" ), path( "local/<str:file_id>/", FilePassThruUploadLocalApi.as_view(), name="local" ) ], "pass-thru")) ) ], "upload")) ) ] ``` Some people prefer the first way of doing it, others prefer the visible tree-like structure. This is up to you & your team.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dmmeteo/django-styleguide-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server