def test_get_post_list_view(self): p_id = self.save_post() self.make_interaction(self.user, "opened", post_id=p_id) self.make_interaction(self.user, "session", post_id=p_id) self.make_interaction(self.user, "sended", post_id=p_id) self.make_interaction(self.user, "used", post_id=p_id) self.make_interaction(self.user, "feedback", post_id=p_id) request = self.factory.get('/posts/list/') request.user = self.user response = PostsListView.as_view()(request) eq_(response.status_code, 200)
#from django.urls import path from django.conf.urls import url from posts.views import PostsListView, PostsView helper_patterns = [ url(r'^posts/$', PostsListView.as_view(), name='posts'), url(r'^posts/(?P<pk>[0-9]+)/$', PostsView.as_view(), name='get_posts') # ] urlpatterns = helper_patterns
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 posts.views import PostsListView, json_list_published_posts, PostsListOneCategoryView, AboutApiListView from posts.api import views as api_views urlpatterns = [ path('admin/', admin.site.urls), path('', PostsListView.as_view(), name='main'), path('category/<cat>/', PostsListOneCategoryView.as_view(), name='posts_with_one_category'), path('api-old/posts/', json_list_published_posts), path('api/posts/', api_views.PostListView.as_view(), name='api_post_list'), path('api/posts/<pk>', api_views.PostDetailView.as_view(), name='api_post_detail'), path('api/category/<slug>/', api_views.PostListViewOneCategory.as_view(), name='api_category_list'), path('about_api/', AboutApiListView.as_view(), name='api') # path('api/posts/category/<pk>', api_views.CategoryListView.as_view(), name='api_category_list' ) ]
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. 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.views.static import serve from posts.views import PostsListView, PostsDetailView, PostsCreateView, PostUpdateView, like urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', PostsListView.as_view()), url(r'^posts/(?P<pk>\d+)/$', PostsDetailView.as_view()), url(r'^posts/create/$', PostsCreateView.as_view()), url(r'^posts/(?P<pk>\d+)/edit/$', PostUpdateView.as_view()), url(r'^like/$', like), ] if settings.DEBUG: urlpatterns += [ url(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}) ]
from DjangoLibre.urls import path from posts.views import PostsListView, PostAddCreateView, PostsUpdateView, PostsDeleteView, PostsDetailView app_name = 'posts' urlpatterns = [ path('posts', PostsListView.as_view(), name='listposts'), path('addposts', PostAddCreateView.as_view(), name='addposts'), path('posts/<int:pk>/alterar', PostsUpdateView.as_view(), name='updateposts'), path('posts/<int:pk>/apagar', PostsDeleteView.as_view(), name='deleteposts'), path('posts/<int:pk>/detail', PostsDetailView.as_view(), name='detailposts'), ]
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 posts.views import PostsListView, json_list_published_posts, CategoryListView, CategoryPostsListView, CategoryPostsListView, PostView from posts.api import views as api_views from django.conf.urls.static import static urlpatterns = [ path('admin/', admin.site.urls), path('', PostsListView.as_view()), path('post/<int:pk>', PostView.as_view(), name="postdetail"), path("<category>", CategoryPostsListView, name="categoryPosts"), path('categories/', CategoryListView.as_view(), name="categories"), # path('api/posts/', json_list_published_posts), path("api/posts/", api_views.PostListView.as_view(), name="api_post_list"), path("api/posts/<pk>", api_views.PostDetailView.as_view(), name="api_post_detail"), path("api/categories/", api_views.CategoryListView.as_view(), name="api_category_list"), path("api/categories/<category>", api_views.CategoryPostDetailView.as_view(), name="api_categorypost_list"), ]
from django.urls import path from users import views as user_views from posts.views import ( index, PostsListView, PostDetailView, PostCreateView, PostUpdateView, PostDeleteView ) urlpatterns = [ path('', user_views.ProfileView.as_view(), name='index'), path('profile/<int:pk>/update/', user_views.ProfileUpdateView.as_view(), name='profile-update'), 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('posts/<category>/', PostsListView.as_view(), name='posts-list'), ]
"""gregsblog 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.conf import settings from django.conf.urls.static import static from django.contrib import admin from django.urls import include, path from posts.views import PostsDetailView, PostsListView from sitepages.views import CoverPageView urlpatterns = [ path("back/", admin.site.urls), path("home/", PostsListView.as_view(), name="home"), path("posts/<slug:slug>/", PostsDetailView.as_view(), name="post_detail"), path("", CoverPageView.as_view(), name="cover"), path("", include("sitepages.urls", namespace="sitepages")), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from posts.views import post_detail, new_post, LatestPostsView, PostsListView, BlogsListView, UserPostsView from users.api import UserDetailAPI, UserAPI from users.views import login, logout, SignUpFormView urlpatterns = [ path('admin/', admin.site.urls), # Users path('login', login, name='login'), path('logout', logout, name='logout'), path('signup', SignUpFormView.as_view(), name='signup'), # posts path('blogs/<str:name>/<int:pk>/', post_detail, name='post_detail'), path('blogs/<str:name>/', UserPostsView.as_view(), name='blog_user'), path('all_posts', PostsListView.as_view(), name='post_list'), path('post/new/', new_post, name='new_post'), # blogs path('blogs', BlogsListView.as_view(), name='blogs'), # home path('', LatestPostsView.as_view(), name='home'), # API path('api/posts/<int:pk>', PostDetailAPI.as_view(), name='post_detail_api'), path('api/posts/<str:name>', PostsAPI.as_view(), name='posts_api'), path('api/users/<int:pk>', UserDetailAPI.as_view(), name='user_detail_api'), path('api/users', UserAPI.as_view(), name='posts_api')
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 posts.views import PostsListView, json_list_published_posts, take_posts_by_category from posts.api import views as api_views urlpatterns = [ path('admin/', admin.site.urls), path('', PostsListView.as_view(), name="main"), path('', take_posts_by_category, name="take_category"), path('<category>', PostsListView.as_view(), name="list_by_category"), #path('api/posts/', json_list_published_posts), path("api/posts/", api_views.PostListView.as_view(), name="api_post_list"), path("api/posts/<pk>", api_views.PostDetailView.as_view(), name="api_post_detail"), path("api/category/", api_views.CategoryListView.as_view(), name="api_category_list"), path("api/category/<category>", api_views.CategoryView.as_view(), name="api_category_post") ]