Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.urls import path, include from rest_framework.authtoken.views import obtain_auth_token from api.views import GetAuthToken from django.conf import settings from django.conf.urls.static import static urlpatterns = [ path('api/', include('api.urls')), path('admin/', admin.site.urls), path('auth/', GetAuthToken.as_view()) ] if settings.DEBUG: urlpatterns += static( settings.STATIC_URL, document_root=settings.STATIC_ROOT ) urlpatterns += static( settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.conf.urls import include from django.urls import path from django.contrib import admin from rest_framework import routers from api import views from api.views import GetAuthToken from django.conf.urls.static import static from django.conf import settings router = routers.DefaultRouter() router.register(r'api/news', views.NewsViewSet) router.register(r'api/users', views.UsersViewSet) router.register(r'api/profile', views.PersonViewSet) router.register(r'api/contact', views.ContactViewSet) urlpatterns = [ path('admin/', admin.site.urls), path(r'', include(router.urls)), path('api/chat/', include('api.urls', namespace='chat')), path(r'api/auth/', GetAuthToken.as_view()), ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
router.register(r'regional-project', deployment_views.RegionalProjectViewset) router.register(r'project', deployment_views.ProjectViewset) admin.site.site_header = 'IFRC Go administration' admin.site.site_title = 'IFRC Go admin' urlpatterns = [ url(r'^api/v1/es_search/', EsPageSearch.as_view()), url(r'^api/v1/es_health/', EsPageHealth.as_view()), url(r'^api/v1/graphql/', GraphQLView.as_view(graphiql=True)), url(r'^api/v1/aggregate/', AggregateByTime.as_view()), url(r'^api/v1/aggregate_dtype/', AggregateByDtype.as_view()), url(r'^api/v1/aggregate_area/', AreaAggregate.as_view()), url(r'^api/v2/create_field_report/', api_views.CreateFieldReport.as_view()), url(r'^api/v2/update_field_report/(?P<pk>\d+)/', api_views.UpdateFieldReport.as_view()), url(r'^get_auth_token', GetAuthToken.as_view()), url(r'^api/v2/update_subscriptions/', UpdateSubscriptionPreferences.as_view()), url(r'^api/v2/add_subscription/', AddSubscription.as_view()), url(r'^api/v2/del_subscription/', DelSubscription.as_view()), url(r'^register', NewRegistration.as_view()), url(r'^sendperform', FormSent.as_view()), url(r'^editperform', FormEdit.as_view()), url(r'^sendperdraft', DraftSent.as_view()), url(r'^sendperoverview', OverviewSent.as_view()), url(r'^sendperworkplan', WorkPlanSent.as_view()), url(r'^api/v2/del_perworkplan', DelWorkPlan.as_view()), url(r'^api/v2/del_peroverview', DelOverview.as_view()), url(r'^api/v2/del_perdraft', DelDraft.as_view()), url(r'^verify_email', VerifyEmail.as_view()), url(r'^validate_user', ValidateUser.as_view()), url(r'^change_password', ChangePassword.as_view()),
from rest_framework import routers from api.views import RegistrationViewSet, EvaluatorViewSet, CandidateViewSet, EventViewSet, GetAuthToken from django.urls import path router = routers.SimpleRouter() urlpatterns = [path("login/", GetAuthToken.as_view())] router.register("candidates", CandidateViewSet) router.register("evaluators", EvaluatorViewSet) router.register("registration", RegistrationViewSet) router.register("event", EventViewSet) urlpatterns = urlpatterns + router.urls