def test_delete_permitted(self): request = self.factory.get('/foo-slug/~delete') request.user = self.user assign_perm('articles.view_article', self.user, self.article) assign_perm('articles.delete_article', self.user, self.article) view = ArticleDeleteView.as_view() response = view(request, slug='foo-slug') self.assertEqual(response.status_code, 200)
from django.conf.urls import url from articles.views import (ArticleCreateView, ArticleDeleteView, ArticleListView, ArticleUpdateView, CategoryArticlesListView, CategoryCreateView, CategoryDeleteView, CategoryListView, CategoryUpdateView, TagCreateView, TagDeleteView, TagListView, TagUpdateView) urlpatterns = [ url(r'^$', ArticleListView.as_view(), name='list'), url(r'^create/$', ArticleCreateView.as_view(), name='create'), url(r'^(?P<pk>\d+)/$', ArticleUpdateView.as_view(), name='detail'), url(r'^(?P<pk>\d+)/delete/$', ArticleDeleteView.as_view(), name='delete'), url(r'^category/$', CategoryListView.as_view(), name='category-list'), url(r'^category/create/$', CategoryCreateView.as_view(), name='category-create'), url(r'^category/(?P<pk>\d+)/$', CategoryUpdateView.as_view(), name='category-detail'), url(r'^category/articles/(?P<pk>\d+)/$', CategoryArticlesListView.as_view(), name='category-articles-list'), url(r'^category/(?P<pk>\d+)/delete/$', CategoryDeleteView.as_view(), name='category-delete'), url(r'^tags/$', TagListView.as_view(), name='tag-list'), url(r'^tags/create/$', TagCreateView.as_view(), name='tag-create'), url(r'^tags/(?P<pk>\d+)/$', TagUpdateView.as_view(), name='tag-detail'), url(r'^tags/(?P<pk>\d+)/delete/$',
def test_delete_denied(self): request = self.factory.get('/foo/~delete') request.user = self.user view = ArticleDeleteView.as_view() response = view(request, slug='foo-slug') self.assertEqual(response.status_code, 302)
from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() from articles.views import ArticleListView, ArticleAddView from articles.views import ArticleDetailView from articles.views import ArticleEditView, ArticleDeleteView from profiles.views import UserProfileView, UserProfileEditView from django.contrib.auth.decorators import login_required urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), url(r'^$', ArticleListView.as_view(), name="home"), url(r'^articles/add/$', login_required(ArticleAddView.as_view()), name='article_add'), url(r'^articles/(?P<slug>.+)/edit/$', login_required(ArticleEditView.as_view()), name='article_edit'), url(r'^articles/(?P<slug>.+)/delete/$', login_required(ArticleDeleteView.as_view()), name='article_delete'), url(r'^articles/(?P<slug>.+)/$', ArticleDetailView.as_view(), name='article_detail'), url(r'^login/$', "django.contrib.auth.views.login", { "template_name": "login.html" }, name="login"), url(r'^logout/$', "django.contrib.auth.views.logout_then_login", name="logout"), url(r'^accounts/', include("registration.backends.simple.urls")), url(r'^users/(?P<slug>\w+)/$', UserProfileView.as_view(), name="profile"), url(r'^edit_profile/$', login_required(UserProfileEditView.as_view()), name="edit_profile"), )
from django.urls import path from articles.views import ArticleListView, ArticleUpdateView, ArticleDetailView, ArticleDeleteView, ArticleCreateView urlpatterns = [ path('<int:pk>/edit/', ArticleUpdateView.as_view(), name='article_edit'), path('<int:pk>/', ArticleDetailView.as_view(), name='article_detail'), path('<int:pk>/delete/', ArticleDeleteView.as_view(), name='article_delete'), path('new/', ArticleCreateView.as_view(), name='article_new'), path('', ArticleListView.as_view(), name='article_list') ]
The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.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.urls import path from django.contrib import admin from articles.views import ArticleListView, ArticleDetailView, ArticleCreateView, ArticleUpdateView, ArticleDeleteView, CategoryListView, CategoryCreateView from django.conf import settings # 増えた from django.conf.urls.static import static # 増えた urlpatterns = [ path('categorycreate', CategoryCreateView.as_view(), name='categorycreate'), path('category', CategoryListView.as_view(), name='category'), path('delete/<int:pk>', ArticleDeleteView.as_view(), name="delete"), path('create', ArticleCreateView.as_view(), name="create"), path('update/<int:pk>', ArticleUpdateView.as_view(), name="update"), path('<int:pk>', ArticleDetailView.as_view(), name="detail"), path('', ArticleListView.as_view(), name="index"), path('admin/', admin.site.urls), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from users.views import SignUpView from pages.views import HomePageView from articles.views import ( ArticleListView, ArticleUpdateView, ArticleDetailView, ArticleDeleteView, ArticleCreateView, ) urlpatterns = [ path('admin/', admin.site.urls), path('users/', include('django.contrib.auth.urls')), #From users path('users/signup/', SignUpView.as_view(), name='signup'), #From pages path('', HomePageView.as_view(), name='home'), #From articles path('articles/', ArticleListView.as_view(), name='article_list'), path('articles/<int:pk>/edit/', ArticleUpdateView.as_view(), name='article_edit'), path('articles/<int:pk>/', ArticleDetailView.as_view(), name='article_detail'), path('articles/<int:pk>/delete/', ArticleDeleteView.as_view(), name='article_delete'), path('articles/new/', ArticleCreateView.as_view(), name='article_new'), ]
CategoryDeleteView, CategoryListView, CategoryUpdateView, TagCreateView, TagDeleteView, TagListView, TagUpdateView, ) app_name = "articles" urlpatterns = [ url(r"^$", ArticleListView.as_view(), name="list"), url(r"^create/$", ArticleCreateView.as_view(), name="create"), url(r"^(?P<pk>\d+)/$", ArticleUpdateView.as_view(), name="detail"), url(r"^(?P<pk>\d+)/delete/$", ArticleDeleteView.as_view(), name="delete"), url(r"^category/$", CategoryListView.as_view(), name="category-list"), url( r"^category/create/$", CategoryCreateView.as_view(), name="category-create", ), url( r"^category/(?P<pk>\d+)/$", CategoryUpdateView.as_view(), name="category-detail", ), url( r"^category/articles/(?P<pk>\d+)/$", CategoryArticlesListView.as_view(), name="category-articles-list",