def test_get_user_login_view(self): request = self.factory.get('/') response = UserLoginView.as_view()(request) response.render() self.assertEqual(response.status_code, 200) self.assertIn('<label for="id_username">', response.content) self.assertIn('<label for="id_password">', response.content)
def test_post_user_login_view(self): request = self.factory.post(reverse('users:login'), data={ 'username': self.user.username, 'password': self._password, }) self._add_session_to_request(request) response = UserLoginView.as_view()(request) self.assertEqual(response.status_code, 302)
from users.views import UserLoginView from courses.api_views import CourseApiViewSet, NewEnrolleeApiViewSet from discounts.api_views import DiscountApiViewSet # set up rest framework router router = routers.DefaultRouter() router.register(r'courses', CourseApiViewSet) router.register(r'new-enrollee', base_name='new-enrollee', viewset=NewEnrolleeApiViewSet) router.register(r'discount', DiscountApiViewSet) # overwrite admin template variables admin.site.site_header = 'Olade Administration' # default: "Django Administration" admin.site.index_title = 'Administration' # default: "Site administration" admin.site.site_title = 'Olade site admin' # default: "Django site admin" urlpatterns = [ path('', UserLoginView.as_view()), path('api/', include(router.urls)), path('api-auth/', include('rest_framework.urls', namespace='rest_framework')), path('admin/', admin.site.urls), path('chaining/', include('smart_selects.urls')), path('users/', include('users.urls', namespace='users')), path('courses/', include('courses.urls', namespace='courses')), path('payments/', include('payments.urls', namespace='payments')), path('tinymce/', include('tinymce.urls')), ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
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.conf.urls import url from django.views.static import serve from . import settings from django.urls import path, include from django.views.generic import TemplateView import xadmin from users.views import UserLoginView urlpatterns = [ path('admin/', xadmin.site.urls), path('', include('lzapps.center.urls', namespace='center')), # path("", TemplateView.as_view(template_name="peixun/index.html"), name="index"), path('ueditor/', include('DjangoUeditor.urls')), path("login/", UserLoginView.as_view(), name='login'), url(r'^uploads/(?P<path>.*)$', serve, {"document_root": settings.MEDIA_ROOT}), # url(r'^static/(?P<path>.*)$', serve, {"document_root": settings.STATIC_ROOT}), ]
# drf文档,title自定义 path('docs', include_docs_urls(title='Amir')), # users的url re_path(r'', include('users.urls')), # areas de url re_path(r'', include('areas.urls')), # goods 的 url path(r'', include('goods.urls')), # cart de url path('', include('carts.urls')), # oauth的url path('oauth/', include('oauth.urls')), re_path('^', include(router.urls)), # Django REST framework JWT提供了登录签发JWT的视图,可以直接使用 # ps:但是默认的返回值仅有token,我们还需在返回值中增加username和user_id。 path('authorizations/', UserLoginView.as_view()), # 添加ckeditor路由 path('ckeditor/', include('ckeditor_uploader.urls')), # orders 的 url path(r'', include('orders.urls')), ]
from django.urls import path, include from users.views import ProfileView, ProfileEditView, UserLoginView, \ UserLogoutView, UserSignupView app_name = 'users' urlpatterns = [ path('perfil/<int:pk>/', ProfileView.as_view(), name='profile'), path('perfil/<int:pk>/editar/', ProfileEditView.as_view(), name='profile-edit'), path('login/', UserLoginView.as_view(), name="login"), path('logout/', UserLogoutView.as_view(), name="logout"), path('cadastro/', UserSignupView.as_view(), name='signup'), ]
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 django.urls.conf import include from users.views import UserLoginView from django.conf import settings from django.conf.urls.static import static urlpatterns = [ path('admin/', admin.site.urls), path('users/', include('users.urls')), path('mp-operations/', include('mp_operations.urls')), path('constituent-operations/', include('constituent_operations.urls')), path('users/login/', UserLoginView.as_view(), name="login_"), path("general/", include('general.urls')), path("pages/", include('routing.urls')), path("superadmin/", include('superadmin_operations.urls')) ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
from django.urls import path from users.views import UserLoginView from users.views import index, logout_view urlpatterns = [ path('', index, name='index'), path('s/login/', UserLoginView.as_view()), path('s/logout/', logout_view) ]
from django.urls import path from users.views import ( ProfileView, ProfileEditView, UserLoginView, UserLogoutView, UserSignupView, FollowUserView, FollowersUserView, ) app_name = 'users' urlpatterns = [ path('perfil/<int:pk>/', ProfileView.as_view(), name="profile"), path('perfil/<int:pk>/editar/', ProfileEditView.as_view(), name="profile-edit"), path('login/', UserLoginView.as_view(), name="login"), path('logout/', UserLogoutView.as_view(), name="logout"), path('signup/', UserSignupView.as_view(), name="signup"), path('seguir/<int:pk>', FollowUserView.as_view(), name="seguir"), path('perfil/<int:pk>/seguidores', FollowersUserView.as_view(), name="seguidores"), ] #users(app_name):profile(name)
from django.conf.urls import patterns, url, include from collection.views import OrganizationCollectionListView from orgs.views import OrganizationListView from sources.views import OrganizationSourceListView from users.models import UserProfile from users.views import UserListView, UserDetailView, UserReactivateView, UserLoginView from oclapi.models import NAMESPACE_PATTERN __author__ = 'misternando' urlpatterns = patterns('', url(r'^$', UserListView.as_view(), name='userprofile-list'), url(r'^login/$', UserLoginView.as_view(), name='user-login'), url(r'^(?P<user>' + NAMESPACE_PATTERN + ')/$', UserDetailView.as_view(), name='userprofile-detail'), url(r'^(?P<user>' + NAMESPACE_PATTERN + ')/reactivate/$', UserReactivateView.as_view(), name='userprofile-reactivate'), url(r'^(?P<user>' + NAMESPACE_PATTERN + ')/orgs/$', OrganizationListView.as_view(), {'related_object_type': UserProfile, 'related_object_kwarg': 'user'}, name='userprofile-orgs'), url(r'^(?P<user>' + NAMESPACE_PATTERN + ')/orgs/sources/$', OrganizationSourceListView.as_view(), name='userprofile-organization-source-list'), url(r'^(?P<user>' + NAMESPACE_PATTERN + ')/orgs/collections/$', OrganizationCollectionListView.as_view(), name='userprofile-organization-collection-list'), url(r'^(?P<user>' + NAMESPACE_PATTERN + ')/sources/', include('sources.urls')), url(r'^(?P<user>' + NAMESPACE_PATTERN + ')/collections/', include('collection.urls')) )
from users.views import SignupView, logout_user,\ UserLoginView, UserProfileView, UserProfileModifyView from trades.views import SellCreateView, GoodsListView,\ GoodsDetailView, SellUpdateView, OrderPageView, OrderCheckView,\ OrderCompleteView, CommentAttachView, send_email from trades.api import * from users.api import UserCheckAPIView, UserEmailAPIView, CertificateUserPhone, \ CheckCertificatePhone urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', HomeView.as_view(), name="home"), url(r'^signup/$', SignupView.as_view(), name="signup"), url(r'^login/$', UserLoginView.as_view(), name="login"), url(r'^logout/$', logout_user, name="logout"), url(r'^register/goods/$', SellCreateView.as_view(), name="register_goods"), url(r'^sell/list/$', GoodsListView.as_view(), name="goods_list"), url(r'^sell/(?P<slug>\w+)/modify/$', SellUpdateView.as_view(), name="goods_modify"), url(r'^sell/(?P<slug>\w+)/comment/$', CommentAttachAPIView.as_view(), name="attach_comment"), url(r'^sell/(?P<slug>\w+)/$', GoodsDetailView.as_view(), name="goods_detail"), url(r'^api/sell/(?P<pk>\d+)/comment/$', CommentAPIView.as_view(), name="api_sell_comment"), url(r'^api/sell/(?P<pk>\d+)/$', SellDetailAPIView.as_view(), name="api_sell_detail"), url(r'^api/sell/$', SellListAPIView.as_view(), name="api_sell_list"), url(r'^api/user_check/$', UserCheckAPIView.as_view(), name="user_check"), url(r'^api/email_check/$', UserEmailAPIView.as_view(), name="email_check"), url(r'^api/phone_certificate/$', CertificateUserPhone.as_view(), name="phone_check"), url(r'^api/phone_certificate/check/$', CheckCertificatePhone.as_view(), name="phone_certificate"),
"""project URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.1/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 message.views import MessageListCreateView from users.views import UserCreateView, BlockUserView, UnBlockUserView, UserLoginView urlpatterns = [ path("admin/", admin.site.urls), # Users path("user/login/", UserLoginView.as_view(), name="user-login"), path("user/register/", UserCreateView.as_view(), name="user-create"), path("user/block/<str:username>/", BlockUserView.as_view(), name="block-user"), path("user/unblock/<str:username>/", UnBlockUserView.as_view(), name="block-user"), # Messages path("message/<str:username>/", MessageListCreateView.as_view(), name="user-create"), ]
from django.urls import path, include from django.views.generic.base import TemplateView from users.views import UserLoginView, SetPasswordView, UserDetailsView, \ UsersListView, UserSearchView urlpatterns = [ path('', TemplateView.as_view(template_name='home.html'), name='home'), path('login/', include('django.contrib.auth.urls')), path('social_auth/', include('social_django.urls', namespace='social')), path('normal_login/', UserLoginView.as_view(), name='user-login'), path('set_password/', SetPasswordView.as_view(), name='set-password'), path('user/<int:user_id>/', UserDetailsView.as_view(), name='user-details'), path('user/search/', UserSearchView.as_view(), name='user-search') ]
from django.conf.urls import url from users.views import ( UserProfileView, UserLoginView, UserLogoutView, UserRegisterView ) urlpatterns = [ url( r'^login/$', UserLoginView.as_view(), name='login' ), url( r'^logout/$', UserLogoutView.as_view(), name='logout' ), url( r'^register/$', UserRegisterView.as_view(), name='register' ), url( r'^(?P<username>[\w-]+)/$', UserProfileView.as_view(), name='profile' ), ]
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 import routers from users.views import UserViewSet, UserProfileViewSet, UserRegistrationView, UserLoginView from schedule.views import ScheduleViewSet from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView from django.conf.urls import url router = routers.DefaultRouter() router.register(r'users', UserViewSet) router.register(r'profile', UserProfileViewSet) router.register(r'schedule', ScheduleViewSet) # router.register(r'login', UserLoginView.as_view) # router.register(r'api/token', TokenObtainPairView.as_view()) # router.register(r'api/token/refresh', TokenRefreshView.as_view()) urlpatterns = [ url(r'^login', UserLoginView.as_view()), url(r'^signup', UserRegistrationView.as_view()), # path('api/', include(users.urls)), path('api/', include(router.urls)), path('admin/', admin.site.urls), path('api-auth/', include('rest_framework.urls')), path('api/token/', TokenObtainPairView.as_view()), path('api/token/refresh/', TokenRefreshView.as_view()) ]
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. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import url from django.contrib import admin from django.conf import settings from django.conf.urls.static import static from django.conf.urls import include from django.views.static import serve from blog.settings import MEDIA_ROOT from articles.views import ArticleListView from users.views import UserLoginView, UserRegisterView, UserLogoutView urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^login/', UserLoginView.as_view(), name='login'), url(r'^logout/', UserLogoutView.as_view(), name='logout'), url(r'^register/', UserRegisterView.as_view(), name='register'), url(r'^$', ArticleListView.as_view(), name='index'), url(r'^article/', include('articles.urls', namespace='article')), url(r'^media/(?P<path>.*)/$', serve, {"document_root": MEDIA_ROOT}), url(r'^captcha/', include('captcha.urls')), ]
from users.views import UserLoginView, UserLogoutView, IndexView, RegisterView, ActiveUserView, ForgetPwdView, ModifyPwdView, ResetPwdView from organization.views import OrgListView from MxOnline.settings import MEDIA_ROOT # , STATIC_ROOT import xadmin urlpatterns = [ url(r'^xadmin/', xadmin.site.urls), url('^$', IndexView.as_view(), name="index"), url('^login/$', UserLoginView.as_view(), name="login"), url('^logout/$', UserLogoutView.as_view(), name="logout"), url('^register/$', RegisterView.as_view(), name="register"), url('^captcha/', include('captcha.urls')), url('^active/(?P<active_code>.*)/$', ActiveUserView.as_view(), name="user_active"), url('^forgetpwd/$', ForgetPwdView.as_view(), name="forgetpwd"), url('^reset/(?P<reset_code>.*)/$', ResetPwdView.as_view(), name="user_reset"), url('^modifypwd/$', ModifyPwdView.as_view(), name="modifypwd"), url(r'^org/', include('organization.urls', namespace="org")), url(r'^course/', include('course.urls', namespace="course")), url(r'^users/', include('users.urls', namespace="users")), url(r'^ueditor/',include('DjangoUeditor.urls' )), url(r'^media/(?P<path>.*)$', serve, {"document_root":MEDIA_ROOT}), # url(r'^static/(?P<path>.*)$', serve, {"document_root":STATIC_ROOT}), ]
from django.conf import settings from django.conf.urls.static import static from django.contrib import admin from django.urls import path from django.views.generic import TemplateView from users.views import UserJoinView, UserLoginView, UserLogoutView from contents.views import HomeView, GramAddView urlpatterns = [ path("s/a/console/", admin.site.urls), path("", HomeView.as_view()), path("login/", TemplateView.as_view(template_name="login.html")), path("join/", TemplateView.as_view(template_name="join.html")), path("api/users/", UserJoinView.as_view()), path("api/login/", UserLoginView.as_view()), path("api/logout/", UserLogoutView.as_view()), path("api/contents/", GramAddView.as_view()), ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
UserReSendActivationEmailView, UserLoginView, UserDetailView, UserLogoutView, UserChangePasswordView, UserForgotPasswordView, UserResetForgotPasswordView, UserUpdateView, ) app_name = "pages" urlpatterns = [ path("", HomeView.as_view(), name="home-page"), path("search", SearchView.as_view(), name="search-page"), path("login/", UserLoginView.as_view(), name="login-page"), path("register/", UserRegisterView.as_view(), name="register-page"), re_path( r"^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$", UserActivationEmailView.as_view(), name="activate-email-link", ), path( "re-send-activation-link/<str:username>", UserReSendActivationEmailView.as_view(), name="re-send-activate-email-link", ), path("profile/", UserDetailView.as_view(), name="profile-page"), path("update/", UserUpdateView.as_view(), name="update-page"), path("logout/", UserLogoutView.as_view(), name="logout-page"), path("changepassword/",
from django.urls import path from users.views import UserListView, UserLoginView, UserLogoutView, UserSignUpView, UserDetailView app_name = 'users' urlpatterns = [ path('list', UserListView.as_view(), name='list_users'), path('login', UserLoginView.as_view(), name='login_users'), path('logout', UserLogoutView.as_view(), name='logout_users'), path('signup', UserSignUpView.as_view(), name='signup_users'), path('users/<int:pk>/detalhes', UserDetailView.as_view(), name='detail_users'), ]
from django.conf.urls import patterns, url, include from orgs.views import OrganizationListView from users.models import UserProfile from users.views import UserListView, UserDetailView, UserReactivateView, UserLoginView __author__ = 'misternando' urlpatterns = patterns('', url(r'^$', UserListView.as_view(), name='userprofile-list'), url(r'^login/$', UserLoginView.as_view(), name='user-login'), url(r'^(?P<user>[a-zA-Z0-9\-\.]+)/$', UserDetailView.as_view(), name='userprofile-detail'), url(r'^(?P<user>[a-zA-Z0-9\-\.]+)/reactivate/$', UserReactivateView.as_view(), name='userprofile-reactivate'), url(r'^(?P<user>[a-zA-Z0-9\-\.]+)/orgs/$', OrganizationListView.as_view(), {'related_object_type': UserProfile, 'related_object_kwarg': 'user'}, name='userprofile-orgs'), url(r'^(?P<user>[a-zA-Z0-9\-\.]+)/sources/', include('sources.urls')), url(r'^(?P<user>[a-zA-Z0-9\-\.]+)/collections/', include('collection.urls')), )
from django.urls import path from users.views import UserLoginView app_name = 'users' urlpatterns = [ path('login/', UserLoginView.as_view(), name='login'), ]
from source.views import SourceRecommendBookView, SourceRecommendVideoView, PlanTableView, PlanTableViewset, UserRecordView, UserRecordViewset, UserExperienceView, UserExperienceViewset from chat.views import UserChatRecordView, UserChatRecordViewset router = DefaultRouter() router.register(r'plans', PlanTableViewset, base_name="plans") router.register(r'records', UserRecordViewset, base_name="records") router.register(r'experiences', UserExperienceViewset, base_name="experiences") router.register(r'chats', UserChatRecordViewset, base_name="chats") urlpatterns = [ path('xadmin/', xadmin.site.urls), re_path(r'docs/', include_docs_urls(title='一路考研', authentication_classes=[], permission_classes=[])), re_path(r'^', include(router.urls)), re_path(r'^users/getlist', UserProfileListView.as_view()), re_path(r'^users/login', UserLoginView.as_view()), re_path(r'^users/logout', UserLoginOutView.as_view()), re_path(r'^users/checklogin', UserCheckLoginView.as_view()), re_path(r'^users/register', UserRegisterView.as_view()), re_path(r'^users/update/(?P<update_filed>.*)/$', UserUpdateView.as_view()), re_path(r'^source/book', SourceRecommendBookView.as_view()), re_path(r'^source/video', SourceRecommendVideoView.as_view()), re_path(r'^source/aims_plan', PlanTableView.as_view()), re_path(r'^source/aims_record', UserRecordView.as_view()), re_path(r'^source/aims_experience', UserExperienceView.as_view()), re_path(r'^source/chats', UserChatRecordView.as_view()), # re_path(r'^source/plan/(?P<pk>.*)/$', PlanTableViewset.as_view({"get":"list", "post":"create", "put":"update", "delete":"destroy"})), ]