def test_user_post_list_view(factory, user): path = reverse('user-posts', kwargs={'username': '******'}) request = factory.get(path) request.user = user view = UserPostListView.as_view() response = view(request, *[], username='******') assert response.status_code == 200
from django.urls import path from . import views from blog.views import (PostListView, PostDetailView, PostCreateView, PostUpdateView, PostDeleteView, UserPostListView, AddCommentView, ) urlpatterns = [ path('', PostListView.as_view(), name='blog-home'), path('user/<str:username>', UserPostListView.as_view(), name='user-posts'), path('post/<int:pk>/', PostDetailView.as_view(template_name='blog/post_detail.html'), name='post-detail'), path('post/<int:pk>/comment/', AddCommentView.as_view(template_name='blog/add_comment.html'), name='post_comment'), path('post/<int:pk>/update/', PostUpdateView.as_view(), name='post-update'), path('post/<int:pk>/delete/', PostDeleteView.as_view(template_name='blog/post_confirm_delete.html'), name='post-delete'), path('post/new/', PostCreateView.as_view(template_name='blog/post_form.html'), name='post-create'), path('about/', views.about, name='blog-about'), ]
from django.urls import path from blog.views import (PostListView, PostDetailView, PostCreateView, PostUpdateView, PostDeleteView, UserPostListView) from blog import views urlpatterns = [ path('', PostListView.as_view(), name="blog-home"), path('user/<str:username>/', UserPostListView.as_view(), name="user-posts"), path('post/<int:pk>/', PostDetailView.as_view(), name="post-detail"), path('post/new/', PostCreateView.as_view(), name="post-create"), path('post/<int:pk>/update/', PostUpdateView.as_view(), name="post-update"), path('post/<int:pk>/delete/', PostDeleteView.as_view(), name="post-delete"), path('about/', views.about, name="blog-about"), ]
from django.urls import path, include from users import views as user_views from django.contrib.auth import views as auth_views from blog.views import UserPostListView, TagPostListView from django.views.defaults import page_not_found def custom_page_not_found(request): return page_not_found(request, None) urlpatterns = [ path('admin/', admin.site.urls), path('register/', user_views.register, name='register'), path('profile/', user_views.profile, name='profile'), path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'), path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'), path('', include('blog.urls')), path('u/<str:username>/', UserPostListView.as_view(), name="user-view"), path('tag/<str:tag>/', TagPostListView.as_view(), name="tag-view"), path("404/", custom_page_not_found), ] if (settings.DEBUG): urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.urls import path from blog import views from blog.views import (PostCreateView, PostDetailView, PostListView, PostDeleteView, PostUpdateView, UserPostListView) urlpatterns = [ # Since we want it to be the blog homepage we leave the string, blank. path("", PostListView.as_view(), name="blog-home"), path("post/new/", PostCreateView.as_view(), name="post-create"), path("post/<int:pk>/", PostDetailView.as_view(), name="post-detail"), path("post/<int:pk>/update/", PostUpdateView.as_view(), name="post-update"), path("post/<int:pk>/delete/", PostDeleteView.as_view(), name="post-delete"), path("user/<str:username>/", UserPostListView.as_view(), name="user-post"), path("about", views.about, name="blog-about"), ]
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf import settings from django.conf.urls import url, include from django.conf.urls.static import static from django.contrib import admin from blog.views import ProfileView, PostCreateView, PostListView, PostDetailView, UserPostListView, \ CommentListView, MessagesListView, MessagesUserView, UserView, PostUpdateView post_urls = [ url(r'^create/$', PostCreateView.as_view(), name='post-create'), url(r'^update/(?P<pk>[-\w]+)/$', PostUpdateView.as_view(), name='post-update'), url(r'^my/$', UserPostListView.as_view(), name='post-list-user'), url(r'^comments/$', CommentListView.as_view(), name='comment-list-user'), url(r'^(?P<pk>[-\w]+)/$', PostDetailView.as_view(), name='post-detail'), ] messages_urls = [ url(r'^$', MessagesListView.as_view(), name='message_list'), url(r'^(?P<user>[-\w]+)/$', MessagesUserView.as_view(), name='message'), ] urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^accounts/', include('allauth.urls')), url(r'^$', PostListView.as_view(), name='post-list'), url(r'^accounts/profile/$', ProfileView.as_view(), name='profile'), url(r'^user/(?P<pk>[-\w]+)/$', UserView.as_view(), name='profile-public'),
from django.urls import path from blog import views from blog.views import PostListView, PostDeleteView, UserPostListView, PostCreateView, PostUpdateView #PostDetailView app_name = 'blog' urlpatterns = [ path('', PostListView.as_view(), name='blogHome'), path('posts/<username>/', UserPostListView.as_view(), name='user_posts'), path('<int:pk>/', views.blogPost, name='blogPost'), path('profile/', views.profile, name='profile'), path('new/', PostCreateView.as_view(), name='new'), path('post_update/<int:pk>/', PostUpdateView.as_view(), name="post_update"), path('delete/<int:pk>/', PostDeleteView.as_view(), name='delete'), path('comment/<int:sno>/', views.comment, name="comment") ] # Class Based Views Look ForThe Below Template By Default: # <appname>/<model>_<viewtype>.html # path('<int:pk>/', PostDetailView.as_view(), name='blogPost') # path('new/', views.new, name='new') # path('post_update/<int:sno>/', views.post_update, name="post_update")
path('<slug:slug>', PostView.as_view(), name="post"), path('profile/<slug:username>/', ProfileView.as_view(), name='profile'), #Auth System path('account/signin/', LoginView.as_view(template_name='auth/login.html', redirect_authenticated_user=True, extra_context={'title_page':'Sign in', 'breadcrumb':[(reverse_lazy('home'),'Inicio'), ('','Iniciar Sesión')]} ), name='signin'), path('account/logout/', LogoutView.as_view(), name='logout'), path('account/signup/', register_view, name='signup'), path('account/<slug:pt>/', UserPostListView.as_view(), name='user_post'), path('account/<slug:pt>/new', PostCreateView.as_view(), name='user_post_new'), path('account/<slug:pt>/<slug:slug>/edit', PostUpdateView.as_view(), name='user_post_edit'), path('account/<slug:pt>/<slug:slug>/delete', PostDeleteView.as_view(), name='user_post_delete'), path('ckeditor/', include('ckeditor_uploader.urls')), path('select2/', include('django_select2.urls')), path('activate/<str:uidb64>/<str:token>', activate, name='activate'), #Api path('api/', include('api.urls')), ] if settings.DEBUG: #static = Funcion auxiliar para devolver un patron de URL para servir archivos en modo debug urlpatterns += static(settings.STATIC_URL, document_root= settings.STATIC_ROOT)
from django.urls import path from blog.views import UserPostListView from .views import UserListView urlpatterns = [ path('', UserListView.as_view(), name='user-all'), path('<username>/', UserPostListView.as_view(), name='user-profile'), ]
PostCreateView, PostUpdateView, PostDeleteView, about, ) from users.forms import ForgotPasswordForm from users.views import( signup, profile ) urlpatterns = [ path('admin/', admin.site.urls), path('', PostListView.as_view(), name="blog-home"), path('user-profile/', profile, name="user-profile"), path('<str:username>-posts/', UserPostListView.as_view(), name="userposts-list"), path('post-<int:pk>/', PostDetailView.as_view(), name="post-detail"), path('new-post/', PostCreateView.as_view(), name="post-create"), path('post-<int:pk>/update/', PostUpdateView.as_view(), name="post-update"), path('post-<int:pk>/delete/', PostDeleteView.as_view(), name="post-delete"), path('about/', about, name="blog-about"), path('signup/', signup, name="user-signup"), path('signin/', LoginView.as_view(template_name="users/signin.html"), name="user-signin"), path('signout/', LogoutView.as_view(template_name="users/signout.html"), name="user-signout"), path('password-reset/', PasswordResetView.as_view(template_name="users/password_reset.html", form_class=ForgotPasswordForm), name="password_reset"), path('password-reset/done/', PasswordResetDoneView.as_view(template_name="users/password_reset_done.html"), name="password_reset_done"), path('password-reset/confirm/<uidb64>/<token>/', PasswordResetConfirmView.as_view(template_name="users/password_reset_confirm.html"), name="password_reset_confirm"), path('password-reset/complete/', PasswordResetCompleteView.as_view(template_name="users/password_reset_complete.html"), name="password_reset_complete"), path('password-change/', PasswordChangeView.as_view(template_name="users/password_change.html"), name="password_change"), path('password-change/done/', PasswordChangeDoneView.as_view(template_name="users/password_change_done.html"), name="password_change_done"), ]