def test_article_view(rf): request = rf.get("/article", HTTP_ACCEPT='application/json') view = ArticleView() view.kwargs = {} response = view.get(request, HTTP_ACCEPT='application/json') content = json.loads(response.content) assert 'articles' in content assert len(content['articles']) > 0 assert content['articles'][0] is not None
def test_article_return_template(rf): request = rf.get("/article/10-promise") view = ArticleView() view.kwargs = { 'slug': '10-promise' } response = view.get(request) assert response._headers['content-type'] == ( 'Content-Type', 'text/html; charset=utf-8' ) assert '<!DOCTYPE html>' in str(response.content)
def test_article_view_uuid(rf): request = rf.get("/article/10-promise", HTTP_ACCEPT='application/json') view = ArticleView() view.kwargs = { 'uuid': 'd6397ee8-c4da-11e7-a496-0050569d4be0' } response = view.get(request) content = json.loads(response.content) assert 'articles' in content assert len(content['articles']) == 1 assert content['articles'][0] is not None
def test_article_view_slug(rf): request = rf.get("/article/10-promise", HTTP_ACCEPT='application/json') view = ArticleView() view.kwargs = { 'slug': '10-promise' } response = view.get(request) content = json.loads(response.content) assert 'articles' in content assert len(content['articles']) == 1 assert content['articles'][0] is not None
from django.conf.urls import patterns, url from articles.views import ArticleView urlpatterns = patterns( '', url(r'^articles/(?P<article_slug>[\w\d-]+)/$', ArticleView.as_view(), name='article'), )
"""gamesreview URL Configuration 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.contrib import admin from django.urls import path from articles.views import HomeView, ArticleView, ArticleListView from django.conf import settings from django.conf.urls.static import static urlpatterns = [ path('admin/', admin.site.urls, name='admin'), path('', HomeView.as_view()), path('page<int:page>', ArticleListView.as_view()), path('article/<slug:slug>', ArticleView.as_view(), name='article'), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
"""blog URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.9/topics/http/urls/ Examples: Function views 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, include from django.contrib import admin from articles.views import IndexView, ArticleView, SubscribeView, ResourcesView urlpatterns = [ url(r'^resources', ResourcesView.as_view()), url(r'^subscribe', SubscribeView.as_view()), url(r'^(?P<slug>[-\w]+)', ArticleView.as_view()), url(r'^$', IndexView.as_view()), ]
"""blog URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.9/topics/http/urls/ Examples: Function views 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, include from django.contrib import admin from articles.views import IndexView, ArticleView, SubscribeView, ResourcesView urlpatterns = [ url(r'^resources', ResourcesView.as_view()), url(r'^subscribe', SubscribeView.as_view()), url(r'^(?P<slug>[-\w]+)', ArticleView.as_view()), url(r'^$', IndexView.as_view()), ]
# Django imports. from django.urls import path # App imports. from articles.views import ( ArticlesListView, MagazinesListView, UserArticlesView, MagazineArticlesView, ArticleView ) urlpatterns = [ # Route to fetch all articles. path(r'articles/', ArticlesListView.as_view(), name='article-list'), # Route to fetch all magazines. path(r'magazines/', MagazinesListView.as_view(), name='magazine-list'), # Route to fetch all the articles of a Author/User. path(r'authors/<int:user_id>/articles/', UserArticlesView.as_view(), name='author-articles'), # Route to fetch all the articles related to the Magazine. path(r'magazines/<int:magazine_id>/articles/', MagazineArticlesView.as_view(), name='magazine-articles'), # Route to retrieve, update and delete an Article path(r'articles/<int:article_id>/', ArticleView.as_view(), name='article'), ]
# coding=utf8 from django.conf.urls import url from articles.views import ArticleView, ArticleDetailView, WriteView, AddCommentsView urlpatterns = [ #url(r'^$',ArticleView.as_view(),name='article'), # 对应科页面 url(r'^(?P<type_id>\d+)/$', ArticleView.as_view(), name='article_type'), # 对应科页面详情页 url(r'^(?P<type_id>\d+)/(?P<num_id>\d+)', ArticleDetailView.as_view(), name='article_detail'), # 留言也 url(r'^write/$', WriteView.as_view(), name='write'), # 评论 url(r"^addcomment/$", AddCommentsView.as_view(), name='add_comment'), ]
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.urls.static import static from django.contrib import admin from django.conf import settings from django.urls import include, path from articles.views import ArticleView, IndexView, CategoryView urlpatterns = [ path('admin/', admin.site.urls), path('articles/<slug:slug>', ArticleView.as_view(), name="article_path"), path('articles/category/<str:name_category>', CategoryView.as_view(), name="category"), path('martor/', include('martor.urls')), path('', IndexView.as_view(), name="main_page", ) ] \ + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) if settings.DEBUG: import debug_toolbar urlpatterns = [ path('__debug__/', include(debug_toolbar.urls)), ] + urlpatterns
from categorys.views import IndexView, AboutView, GuestbookView, CateArtListView from articles.views import ArticleView urlpatterns = [ # url(r'^$', TemplateView.as_view(template_name='index.html')), url(r'^$', IndexView.as_view(), name="index"), url(r'^about/', AboutView.as_view(), name="about"), url(r'^guestbook/', GuestbookView.as_view(), name="guestbook"), url(r'^admin/', admin.site.urls), url(r'^xadmin/', xadmin.site.urls), # 分类文章列表 url(r'^cate/(?P<cate_id>\d+)/$', CateArtListView.as_view(), name="cate_art_list"), # 分类文章列表 url(r'^article/(?P<art_id>\d+)/$', ArticleView.as_view(), name="article"), # 配置上传文件的访问处理函数 url(r'^media/(?P<path>.*)$', serve, {"document_root": MEDIA_ROOT}), # 配置静态文件的访问处理函数 url(r'^static/(?P<path>.*)$', serve, {"document_root": STATIC_ROOT}), # DjangoUeitor url(r'^ueditor/', include('DjangoUeditor.urls')), ] # 可以不进行配置,直接在templates里放置404.html,便会自动使用404模板 # 全局404页面配置, 指定如果发生404,调用那个函数 handler404 = 'users.views.page_not_found_404' handler500 = 'users.views.page_error_500'
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.urls import url from django.contrib import admin from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.views import LoginView, LogoutView from django.urls import path from articles import views from articles.views import HomeView, PaidView, ArticleListView, ArticleView urlpatterns = [ path('admin/', admin.site.urls), path('', HomeView.as_view(), name='index'), path('login/', LoginView.as_view(template_name='login.html', authentication_form=AuthenticationForm), name='login'), path('logout/', LogoutView.as_view(template_name='index.html'), name='logout'), path('articles/', ArticleListView.as_view(), name='articles'), # path('articles/', views.show_articles, name='articles'), path('article/<pk>/', ArticleView.as_view(), name='article'), # url(r'^articles/(?P<id>[0-9]+)/', views.show_article, name='article'), path('subscribe-paid/', PaidView.as_view(), name='subscribe_paid') ]
from django.conf.urls import patterns, url from articles.views import ArticleView, ArticleListView urlpatterns = patterns('', url(r'^list/(?P<pk>\d+)/$', ArticleView.as_view(), name='detail'), url(r'^list/$', ArticleListView.as_view(), name='list'), )
# -*- encoding: utf-8 -*- from django.conf.urls import url, include from rest_framework.routers import DefaultRouter from articles.api import ArticleViewSet, ArticleOnlyByUserView from articles.views import HomeView, ArticleView, ArticlesByUserView, ArticlesByCategoryView, ArticlesBySearchQueryView router = DefaultRouter() router.register('apiv1/article', ArticleViewSet, 'api_articles_') articles_urls = [ # Urls WEB url(r'^$', HomeView.as_view(), name='site_home'), url(r'^category\/(?P<slug>[A-Za-z0-9.\+@_-]+)\/$', ArticlesByCategoryView.as_view(), name='articles_by_category'), url(r'^search\/$', ArticlesBySearchQueryView.as_view(), name='articles_by_search_query'), url(r'^(?P<nombre_de_usuario>[A-Za-z0-9.\+@_-]+)\/$', ArticlesByUserView.as_view(), name='articles_by_user'), url(r'^(?P<nombre_de_usuario>[A-Za-z0-9.\+@_-]+)\/(?P<articulo_slug>[A-Za-z0-9.\+@_-]+)$', ArticleView.as_view(), name='article_detail'), # URLS APis url(r'', include(router.urls)), url(r'^apiv1/articleuser/$', ArticleOnlyByUserView.as_view()), ]
"""main URL Configuration 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.conf.urls import url from django.contrib import admin from django.urls import path # import views from articles import views from articles.views import ArticleView urlpatterns = [ path('admin/', admin.site.urls), path('articles/', ArticleView.as_view()), url(r'^articles/(?P<pk>[0-9]+)/', views.show_article), ]
from django.conf.urls import url, include from django.contrib.auth.decorators import login_required from articles.views import CreateArticleView, UpdateArticleView, ArticleView, ArticleListView urlpatterns = [ url(r'^create/$', login_required(CreateArticleView.as_view()), name='create_article'), url(r'^update/(?P<pk>[-\w]+)/$', login_required(UpdateArticleView.as_view()), name='update_article'), url(r'^list/$', ArticleListView.as_view(), name='article_list'), url(r'^(?P<pk>[-\w]+)/$', ArticleView.as_view(), name='article'), ]
from django.urls import path from articles.views import ArticleView urlpatterns = [ path('', ArticleView.as_view()), ]
from django.conf.urls import url from users.views import IndexView, AboutView, BlogInputView, BlogsView, page_not_found, page_error from articles.views import ArticleView from tags.views import TagView from classes.views import TypeView from archives.views import ArchivesView from settings import MEDIA_ROOT from django.views.static import serve # from django.contrib import admin urlpatterns = [ # url(r'^admin/', admin.site.urls), url(r'^xadmin/', xadmin.site.urls), url(r'^index/', IndexView.as_view(), name="index"), url(r'^$', IndexView.as_view(), name="index"), url(r"^tags/", TagView.as_view(), name="tags"), url(r"^types", TypeView.as_view(), name="types"), url(r"^archives", ArchivesView.as_view(), name="archives"), url(r"^about", AboutView.as_view(), name="about"), url(r'^blog/', ArticleView.as_view(), name="blog"), url(r"^issue", BlogInputView.as_view(), name="issue"), url(r"^admin", BlogsView.as_view(), name="admin"), # 配置上传函数 url(r'^media/(?P<path>.*)$', serve, {"document_root": MEDIA_ROOT}), ] # 全局404页面配置 handler404 = page_not_found handler500 = page_error