from django.urls import path from blog.views import HomePageView, CreatePostView, UpdatePostView, ListPageView, DeletePostView # enables namespacing app_name = 'blog' urlpatterns = [ path('', HomePageView.as_view(), name='home-page'), path('posts/', ListPageView.as_view(), name='list-page'), path('posts/new/', CreatePostView.as_view(), name='create-page'), path('posts/update/<pk>/', UpdatePostView.as_view(), name='update-page'), path('posts/delete/<pk>/', DeletePostView.as_view(), name='delete-page') ]
url(r'^users/(?P<username>[\w.@+-]+)/posts/$', PostListView.as_view(), name='user'), # all posts of the user url(r'^users/(?P<username>[\w.@+-]+)/subscribe/$', SubscribeView.as_view(), name='subscribe'), url(r'^users/(?P<username>[\w.@+-]+)/unsubscribe/$', UnsubscribeView.as_view(), name='unsubscribe'), url(r'^posts/$', MyPostListView.as_view(), name='posts'), # all posts of a logined user url(r'^posts/(?P<pk>[0-9]+)/$', PostView.as_view(), name='post'), # the post url(r'^posts/add/$', CreatePostView.as_view(), name='create_post'), url(r'^posts/(?P<pk>[0-9]+)/delete$', DeletePostView.as_view(), name='delete_post'), url(r'^posts/(?P<pk>[0-9]+)/get_viewed/$', PostMarkViewedView.as_view(), name='viewed_post'), url(r'^posts/(?P<pk>[0-9]+)/get_unviewed/$', PostMarkViewedView.as_view(get_viewed=False), name='unviewed_post'), ] if settings.DEBUG: import debug_toolbar urlpatterns += [ url(r'^__debug__/', include(debug_toolbar.urls)), ]
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,include from userwork.views import profile from blog.views import blog , blogpost ,AddPostView,UpdatePostView , DeletePostView from django.conf.urls.static import static from django.conf import settings urlpatterns = [ path('admin/', admin.site.urls), path('',include('userwork.urls')), path('accounts',include('django.contrib.auth.urls')), path('profile/',profile,name='profile'), path('blog/',include('blog.urls')), path('blogpost/<int:id>', blogpost , name='blogpost'), path('addpost/',AddPostView.as_view(), name='addpost'), path('blogpost/updatepost/<int:pk>' , UpdatePostView.as_view(), name = 'updatepost'), path('blogpost/<int:pk>/deletepost/' , DeletePostView.as_view(), name = 'deletepost'), ]+ static(settings.MEDIA_URL,document_root=settings.MEDIA_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.urls import path from blog.views import PostListView from blog.views import PostDetailView from blog.views import PostCreateView from blog.views import UpdatePostView from blog.views import DeletePostView from django.conf.urls.static import static from django.conf import settings urlpatterns = [ path('admin/', admin.site.urls), path('', PostListView.as_view(), name='post-list'), path('create/', PostCreateView.as_view(), name='post-create'), path("<pk>/", PostDetailView.as_view(), name='post-detail'), path("<pk>/update/", UpdatePostView.as_view(), name='post-update'), path("<pk>/delete/", DeletePostView.as_view(), name='post-delete'), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static( settings.STATIC_URL, document_root=settings.STATIC_ROOT)
from django.contrib import admin from blog.views import AddPostView, UpdatePostView, DeletePostView from django.conf.urls.static import static from django.conf import settings admin.autodiscover() import hello.views # To add a new path, first import the app: # import blog # # Then add the new path: # path('blog/', blog.urls, name="blog") # # Learn more here: https://docs.djangoproject.com/en/2.1/topics/http/urls/ urlpatterns = [ path("", hello.views.index, name="index"), path("db/", hello.views.db, name="db"), path("admin/", admin.site.urls), path("blog/", include("blog.urls")), path('add_post/', AddPostView.as_view(), name='add_post'), path('post/edit/<int:pk>', UpdatePostView.as_view(), name='update_post'), path('post/<int:pk>/remove', DeletePostView.as_view(), name='delete_post'), path('members/', include('django.contrib.auth.urls')), # This one for django system path('ckeditor/', include('ckeditor_uploader.urls')), # path('members/', include('members.urls')), # This one will be defined in app's urls ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.urls import path from blog.views import (createUser,About_View,PostDetailView,add_comment_to_post,post_publish, PostListView,PostDetailView,CreatePostView,comment_approve, UpdatePostView,DeletePostView,DraftListView,comment_remove) app_name = 'blog' urlpatterns = [ path('signup/',createUser,name='signup'), path('',PostListView.as_view(),name='post_list'), path('post/<int:pk>',PostDetailView.as_view(),name='post_detail'), path('about/',About_View.as_view(),name='about'), path('post/new',CreatePostView.as_view(),name='post_view'), path('post/<int:pk>/edit',UpdatePostView.as_view(),name='post_edit'), path('post/<int:pk>/delete',DeletePostView.as_view(),name='post_delete'), path('drafts/',DraftListView.as_view(),name='drafts_list'), path('post/<int:pk>/comment/',add_comment_to_post,name='add_comment_to_post'), path('comments/<int:pk>/approve',comment_approve,name='comment_approve'), path('comments/<int:pk>/delete',comment_remove,name='comment_remove'), path('post/<int:pk>/publish',post_publish,name='post_publish'), ]
from blog import views from blog.views import AboutView,PostListView,PostDetailView,CreatePostView,UpdatePostView,DeletePostView,DraftListView from django.urls import path urlpatterns = [ path('',PostListView.as_view(),name='post_list'), path('post/<int:pk>/',PostDetailView.as_view(),name='post_detail'), path('post/new/',CreatePostView.as_view(),name='post_new'), path('post/<int:pk>/edit/',UpdatePostView.as_view(),name='post_edit'), path('post/<int:pk>/remove/',DeletePostView.as_view(),name='post_remove'), path('drafts/',DraftListView.as_view(),name='post_draft_list'), path('about/', AboutView.as_view(), name='about'), path('post/<int:pk>/comment/',views.add_comment_to_post,name='add_comment_to_post'), path('comment/<int:pk>/approve/',views.comment_approve,name='comment_approve'), path('comment/<int:pk>/remove/',views.comment_remove,name='comment_remove'), path('post/<int:pk>/publish/',views.post_publish,name='post_publish'), ]