def setUp(self): """Define the test global variables.""" if not User.objects.filter(username='******').exists(): self.admin_user = User.objects.create_superuser( username='******', password='******', email='') Token.objects.create(user=self.admin_user) user = User.objects.create(username='******', email='*****@*****.**', password='******') self.test_profile = Profile.objects.create(user=user) self.factory = APIRequestFactory() self.view = ProfileDetail.as_view()
admin.autodiscover() if settings.DEBUG: urlpatterns = patterns('django.views.static', url(r'^static/(?P<path>.*)$', 'serve', {'document_root': '/tmp/shortdiary-static/', 'show_indexes': True }), url(r'^asset/(?P<path>.*)$', 'serve', {'document_root': '/tmp/shortdiary-asset/', 'show_indexes': True }), ) else: urlpatterns = patterns('') api_patterns= format_suffix_patterns(patterns('', url(r'^posts/$', PostList.as_view(), name="api-post-list"), url(r'^posts/(?P<pk>\d+)/$', PostDetail.as_view(), name='api-post-detail'), url(r'^public/$', PublicPostDetail.as_view(), name='api-public-post'), url(r'^profile$', ProfileDetail.as_view(), name='api-profile-detail'), ), allowed=["json", "html"]) urlpatterns += patterns('', url(r'^admin/doc/', include('django.contrib.admindocs.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^i18n/setlang/(?P<language>[a-z]+)', 'diary.views.switch_language'), url(r'^accounts/login/$', 'diary.views.login'), url(r'^accounts/logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}), url(r'^accounts/signup/$', 'diary.views.sign_up'), url(r'^accounts/settings/$', 'diary.views.account_settings'), url(r'^invite/$', 'inviteman.views.invite'), url(r'^invite/request/$', 'inviteman.views.invite_request'),
# Imports #--------------------------------------------------------- from api.views import ProfileList, ProfileDetail from api.views import NewsList, NewsDetail from api.views import ReaderList, ReaderDetail from api.views import SystemList, SystemDetail from api.views import ChangeList, ChangeDetail from django.urls import path from rest_framework.urlpatterns import format_suffix_patterns from api import views #--------------------------------------------------------- # Url Paths #--------------------------------------------------------- urlpatterns = [ path('profile/', ProfileList.as_view(), name='profile-list'), path('profile/<int:pk>/', ProfileDetail.as_view(), name='profile-detail'), path('news/', NewsList.as_view(), name='news-list'), path('news/<int:pk>/', NewsDetail.as_view(), name='news-detail'), path('reader/', ReaderList.as_view(), name='reader-list'), path('reader/<int:pk>/', ReaderDetail.as_view(), name='reader-detail'), path('system/', SystemList.as_view(), name='system-list'), path('system/<int:pk>/', SystemDetail.as_view(), name='system-detail'), path('change/', ChangeList.as_view(), name='change-list'), path('change/<int:pk>/', ChangeDetail.as_view(), name='change-detail'), ] urlpatterns = format_suffix_patterns(urlpatterns)
Examples: 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, re_path from rest_framework.authtoken import views from api.views import RouteList, RouteDetail, ProfileDetail, LeaderboardView api_urlpatterns = [ path('accounts/', include('rest_registration.api.urls')), path('routes/', RouteList.as_view()), path('routes/<int:pk>', RouteDetail.as_view()), path('profiles/<int:pk>', ProfileDetail.as_view()), path('profiles/', ProfileDetail.as_view()), path('leaderboard/', LeaderboardView.as_view()) ] urlpatterns = [ path('admin/', admin.site.urls), path('api/', include(api_urlpatterns)), re_path(r'^api-token-auth/', views.obtain_auth_token), ]
from api.views import UserList, UserDetail, ProfileList, ProfileDetail, JobPostingList, \ JobPostingDetail, JobApplicationList, JobApplicationDetail, InviteViaEmail, ProfileRecommendations, \ EducationDescriptionList, EducationDescriptionDetail, EmploymentDescriptionList, EmploymentDescriptionDetail, \ SkillList, SkillDetail, CompanyList, CompanyDetail, ForgottenPasswordEmail, ResetPassword, Search, RegisterConnection, \ ConnectionList, ProfileImageList, ProfileApplicationIDs, ProfileApplicationList, FeedPostList, UserJobPostingsList, \ ChangePassword, DeleteConnection urlpatterns = [ url(r'^users/$', UserList.as_view()), url(r'^users/(?P<username>[a-zA-Z][a-zA-Z0-9_]+)/$', UserDetail.as_view()), url(r'^users/(?P<username>[a-zA-Z][a-zA-Z0-9_]+)/change-password/$', ChangePassword.as_view()), url(r'^profiles/$', ProfileList.as_view()), url(r'^profiles/(?P<username>[a-zA-Z][a-zA-Z0-9_]+)/$', ProfileDetail.as_view()), url(r'^profiles/(?P<username>[a-zA-Z][a-zA-Z0-9_]+)/recommendations/$', ProfileRecommendations.as_view()), url(r'^profiles/(?P<username>[a-zA-Z][a-zA-Z0-9_]+)/application_ids/$', ProfileApplicationIDs.as_view()), url(r'^jobs/$', JobPostingList.as_view()), url(r'^jobs/(?P<job_id>[0-9]+)/$', JobPostingDetail.as_view()), url(r'^jobs/(?P<job_id>[0-9]+)/applications/$', JobApplicationList.as_view()), url(r'^jobs/(?P<job_id>[0-9]+)/applications/(?P<application_id>[0-9]+)/$', JobApplicationDetail.as_view()), url(r'^send-invite/$', InviteViaEmail.as_view()), url(r'^forgot-password/$', ForgottenPasswordEmail.as_view()), url(r'^reset-password/$', ResetPassword.as_view()), url(r'^search/(?P<query_string>[a-zA-Z0-9_]*)/$', Search.as_view()), url(r'^connect/$', RegisterConnection.as_view()),
from django.urls import path from api.views import ProfileList, ProfileDetail urlpatterns = [ path('profiles/', ProfileList.as_view()), path('profiles/<str:username>', ProfileDetail.as_view()), ]