from django.urls import path from Insta.views import HelloDjango, PostListView, PostDetailView, PostCreateView, PostUpdateView, PostDeleteView, addLike urlpatterns = [ path('test/', HelloDjango.as_view(), name='helloworld'), path('posts/', PostListView.as_view(), name='posts'), path('posts/<int:pk>/', PostDetailView.as_view(), name='post_detail'), path('posts/new/', PostCreateView.as_view(), name='post_create'), path('posts/update/<int:pk>', PostUpdateView.as_view(), name='post_update'), path('posts/delete/<int:pk>', PostDeleteView.as_view(), name='post_delete'), path('like', addLike, name='addLike'), ]
"""InstaDemo URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.2/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, include from Insta.views import PostView, PostDetail, PostCreateView, PostUpdateView, PostDeleteView, SignUpView urlpatterns = [ path('', PostView.as_view(), name='home'), path('post/<int:pk>/', PostDetail.as_view(), name='post_detail'), path('make_post/', PostCreateView.as_view(), name='make_post'), path('update_post/<int:pk>', PostUpdateView.as_view(), name='update_post'), path('delete_post/<int:pk>', PostDeleteView.as_view(), name='delete_post'), path('auth/signup', SignUpView.as_view(), name='signup'), ]
from django.urls import path from Insta.views import HelloWorld, PostsView, PostDetailView, PostCreateView, PostUpdateView, PostDeleteView urlpatterns = [ path('', HelloWorld.as_view(), name='home'), path('posts/', PostsView.as_view(), name="posts"), path('posts/<int:pk>/', PostDetailView.as_view(), name="post_detail"), path('post/new/', PostCreateView.as_view(), name="make_post"), path('post/update/<int:pk>/', PostUpdateView.as_view(), name="update_post"), path('post/delete/<int:pk>/', PostDeleteView.as_view(), name="delete_post"), ]
# We can create "urls.py" for each App and use this method to manage all the urls. 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 include, path from Insta.views import MyView, PostsView, PostDetailView, PostCreateView, PostUpdateView, PostDeleteView, addLike, \ UserDetailView, toggleFollow, EditProfile, addComment, ExploreView urlpatterns = [ path('myview', MyView.as_view(), name='my_view'), path('', PostsView.as_view(), name='posts'), path('posts/<int:pk>/', PostDetailView.as_view(), name='post_detail'), path('posts/new/', PostCreateView.as_view(), name='make_post'), path('posts/update/<int:pk>/', PostUpdateView.as_view(), name='update_post'), path('posts/delete/<int:pk>/', PostDeleteView.as_view(), name='delete_post'), path('like', addLike, name='addLike'), path('user/<int:pk>/', UserDetailView.as_view(), name='user_detail'), path('togglefollow', toggleFollow, name='togglefollow'), path('user/<int:pk>/edit_profile', EditProfile.as_view(), name='edit_profile'), path('comment', addComment, name='addComment'), path('explore', ExploreView.as_view(), name='explore'), ]
"""InstaDemo URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.2/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, include from Insta.views import PostView, PostDetail, PostCreateView, PostUpdateView, PostDeleteView urlpatterns = [ path('', PostView.as_view(), name='home'), path('post/<int:pk>/', PostDetail.as_view(), name='post_detail'), path('make_post/', PostCreateView.as_view(), name='make_post'), path('update_post/<int:pk>/', PostUpdateView.as_view(), name='update_post'), path('delete_post/<int:pk>/', PostDeleteView.as_view(), name='delete_post'), ]
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 # 1. 从Insta这个app里面import HelloWord这个View 2.and PostsView 3.and PostDetailView from Insta.views import HelloWorld, PostsView, PostDetailView, PostCreateView, PostUpdateView, PostDeleteView, addLike, UserDetailView urlpatterns = [ # 这里是app里的url, 那应该用fuction views, class-based views, or including another URLconf? # 因为 class HelloWorld是一个class-based views, 所以用这个 # 当传入''作为默认路径时,会调HelloWord这个View的as_View(), 因为as_View()方法继承里TemplateView,可以直接用,把'test.html' render出来 path('Hellworld', HelloWorld.as_view(), name='Bello Papagena'), # 当传入post/作为路径时,会调PostsView这个View的as_View(), eg. http://localhost:8000/Insta/posts/ path('', PostsView.as_view(), name='posts'), # 如果传进来的path/并且加一个int,那我就用这个int as 'Post'这个model的primary key(ID),然后之后render在html里 path('post/<int:pk>/', PostDetailView.as_view(), name='post_detail'), # 如果传来的path带着的post/new/ 那就调用PostCreatView path('post/new/', PostCreateView.as_view(), name='make_post'), # 同post_detail 如果有人传进来post/update/ID 那就可以update path('post/update/<int:pk>', PostUpdateView.as_view(), name="post_update"), path('post/delete/<int:pk>', PostDeleteView.as_view(), name="post_delete"), path('like', addLike, name='addLike'), path('user/<int:pk>/', UserDetailView.as_view(), name='user_detail'), ]
"""InstalHang URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.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.contrib import admin from django.urls import include,path from Insta.views import HelloWorld, PostView, PostDetailView,PostCreateView,PostUpdateView,PostDeleteView urlpatterns = [ path('', HelloWorld.as_view(), name='helloworld'), path('posts/',PostView.as_view(),name='posts'), path('post/<int:pk>/',PostDetailView.as_view(),name='post_detail'), path('posts/new',PostCreateView.as_view(),name='make_post'), path('post/update/<int:pk>/',PostUpdateView.as_view(),name='post_update'), path('post/dalete/<int:pk>/',PostDeleteView.as_view(),name='post_delete'), ]