from django.urls import path, re_path from django.conf.urls import url from question.views import IndexView, AskView, QuestionView, QuestionListView, VoteView, BestAnswerView, SearchView, TagView app_name = 'question' urlpatterns = [ path('ask/', AskView.as_view()), path('question/<int:id>/', QuestionView.as_view(), name="question"), path('question/vote/', VoteView.as_view(), name="question_vote"), path('question/best/', BestAnswerView.as_view(), name="question_best"), path('question/list/', QuestionListView.as_view(), name="question_vote"), url(r'^search/?$', SearchView.as_view(), name='search'), path('tag/<str:tag>/', TagView.as_view(), name="question_tag"), path('', IndexView.as_view()), ]
from django.urls import path from question.views import QuestionView urlpatterns = [path('', QuestionView.as_view(), name='questions')]
from django.urls import path from question import views as questionView from question.views import QuestionView urlpatterns = [ path('question/', QuestionView.as_view(), name="question"), path('answer/', questionView.answer), path('answer/reset/', questionView.reset_answer), ]
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, re_path from question.views import QuestionView, QuestionByIdView from user.views import UserLoginView, UserSelfView, UserCheckinView, UserRankView urlpatterns = [ path('admin/', admin.site.urls), # 用户接口 path('user/login', UserLoginView.as_view()), path('user/self', UserSelfView.as_view()), path('user/checkin', UserCheckinView.as_view()), path('user/rank', UserRankView.as_view()), # 答题接口 path('question', QuestionView.as_view()), re_path('question/(?P<questionId>\d+)', QuestionByIdView.as_view()), ]
from django.contrib.auth.decorators import login_required from django.views.generic.simple import direct_to_template admin.autodiscover() urlpatterns = patterns('', url(r'^$', TemplateView.as_view(template_name='home.html'), name='home'), url(r'^admin/', include(admin.site.urls)), # authentication url(r'^accounts/login/$', 'django.contrib.auth.views.login', name='login'), url(r'^openid/login/$', 'django_openid_auth.views.login_begin', name='openid-login'), url(r'^login-complete/$', 'django_openid_auth.views.login_complete', name='openid-complete'), url(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/',}, name='logout'), url(r'^deactivate/$', login_required(DeactivateUserView.as_view()), name='deactivate_user'), url(r'^project/$', login_required(ProjectListView.as_view()), name='project_list'), url(r'^project/new/$', login_required(NewProjectView.as_view()), name='project_new'), url(r'^project/(?P<pk>\d+)/$', login_required(ProjectDetailView.as_view()),name='project_detail'), url(r'^project/(?P<pk>\d+)/delete/$', login_required(ProjectDeleteView.as_view()), name='project_delete'), url(r'^project/(?P<pk>\d+)/rename/$', login_required(ProjectChangeTitleView.as_view()),name='project_change_title'), url(r'^project/(?P<pk>\d+)/csv/$', login_required(ProjectDetailCSVView.as_view()),name='project_csv'), url(r'^project/(?P<project>\d+)/pdf/$', login_required(ProjectAnswerViewPDF.as_view()),name='project_pdf'), url(r'^project/(?P<project>\d+)/answers/$', login_required(ProjectAnswerView.as_view()),name='project_answers'), url(r'^project/(?P<project>\d+)/answers/(?P<category>\d+)/$', login_required(ProjectAnswerView.as_view()),name='project_answers'), url(r'^project/(?P<project>\d+)/hardware-software/$', login_required(ComponentView.as_view()), name='hardware-software'), url(r'^project/(?P<project>\d+)/(?P<category>\d+)/$', login_required(QuestionView.as_view()), name='answer_question'), url(r'^features/$',direct_to_template, {'template': 'features.html'},name='features'), url(r'^create/$',direct_to_template, {'template': 'create.html'},name='create'), url(r'^support/$',direct_to_template, {'template': 'support.html'},name='support'), url(r'^resources/$',direct_to_template, {'template': 'resources.html'},name='resources'), )
1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Add an import: from blog import urls as blog_urls 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) """ from django.conf.urls import include, url from django.contrib import admin from question.views import QuestionsListView, QuestionView, QuestionAdd, like, AnswerAdd, popularTags, popularUsers from users.views import LoginRequest, MyUserRegistration, LogoutRequest, UsersListView, UserView urlpatterns = [ url(r"^admin/", include(admin.site.urls)), url(r"^questions/$", QuestionsListView.as_view(), name="question-list"), url(r"^questions/(?P<pk>\d+)/$", QuestionView.as_view(), name="question"), url(r"^login/", LoginRequest, name="login"), url(r"^registration/", MyUserRegistration, name="registration"), url(r"^logout/", LogoutRequest, name="logout"), url(r"^question_add/", QuestionAdd, name="question_add"), url(r"^comment_add/$", AnswerAdd, name="comment_add"), url(r"^users/$", UsersListView.as_view(), name="users-list"), url(r"^users/(?P<pk>\d+)/$", UserView.as_view(), name="user"), url(r"^like/$", like, name="like"), url(r"^populartags/$", popularTags, name="populartags"), url(r"^popularusers/$", popularUsers, name="popularusers"), ]
1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Add an import: from blog import urls as blog_urls 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) """ from django.conf.urls import include, url from django.contrib import admin from question.views import QuestionsListView, QuestionView, QuestionAdd, like, AnswerAdd, popularTags, popularUsers from users.views import LoginRequest, MyUserRegistration, LogoutRequest, UsersListView, UserView urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^questions/$', QuestionsListView.as_view(), name='question-list'), url(r'^questions/(?P<pk>\d+)/$', QuestionView.as_view(), name='question'), url(r'^login/', LoginRequest, name='login'), url(r'^registration/', MyUserRegistration, name='registration'), url(r'^logout/', LogoutRequest, name='logout'), url(r'^question_add/', QuestionAdd, name='question_add'), url(r'^comment_add/$', AnswerAdd, name='comment_add'), url(r'^users/$', UsersListView.as_view(), name='users-list'), url(r'^users/(?P<pk>\d+)/$', UserView.as_view(), name='user'), url(r'^like/$', like, name='like'), url(r'^populartags/$', popularTags, name='populartags'), url(r'^popularusers/$', popularUsers, name='popularusers'), ]
"""rest_api_example URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.0/topics/http/urls/ 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 from question.views import QuestionView urlpatterns = [ path('admin/', admin.site.urls), path('questions/', QuestionView.as_view({'get': 'list'})), ]