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, PostDetailView, PostsView, PostCreateView, PostUpdateView, PostDeleteView, addLike, UserDetailView) urlpatterns = [ path('helloworld', HelloWorld.as_view(), name='helloworld'), path('', PostsView.as_view(), name='posts'), path('post/<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='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'), ]
"""InstaJZ 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 urlpatterns = [path('', HelloWorld.as_view(), name='helloworld')]
from django.contrib import admin from django.urls import include, path from Insta.views import HelloWorld urlpatterns = [ path('', HelloWorld.as_view(), 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 # 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'), ]
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, PostsView, PostDetailView, PostCreateView, PostUpdateView,PostDeleteView, addLike, addComment, UserDetailView, toggleFollow, ExploreView) urlpatterns = [ path('', HelloWorld.as_view(), name='home'), path('posts/', PostsView.as_view(), name='posts'), path('post/<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='post_update'), path('post/delete/<int:pk>/', PostDeleteView.as_view(), name='post_delete'), path('like', addLike, name='addLike'), path('comment', addComment, name='addComment'), path('togglefollow', toggleFollow, name='togglefollow'), path('user/<int:pk>/', UserDetailView.as_view(), name='user_detail'), path('explore', ExploreView.as_view(), name='explore') ]
"""PhotoApp 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 path from django.urls import include, path from Insta.views import HelloWorld urlpatterns = [path('', HelloWorld.as_view(), name='home')]
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 (HelloWorld, PostsView, PostDetailView, PostCreateView, PostUpdateView, PostDeletView, addLike, UserDetailView, EditProfile, toggleFollow) urlpatterns = [ path('HelloWorld',HelloWorld.as_view(),name = 'HelloWorld'), 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 ='post_update'), path('posts/delete/<int:pk>/',PostDeletView.as_view(),name = 'post_delete'), path('like', addLike, name='addLike'), path('user/<int:pk>/',UserDetailView.as_view(),name = 'user_detail'), path('edit_profile/<int:pk>/', EditProfile.as_view(), name='edit_profile'), path('togglefollow', toggleFollow, name='togglefollow'), ]
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, PostsView, PostDetailView, addLike, PostCreateView, PostUpdateView, PostDeleteView, ExploreView, UserDetailView, EditProfile, toggleFollow, addComment) urlpatterns = [ path('helloworld/', HelloWorld.as_view(), name='helloWorld'), #当输入是空的时候返回hello world path('', PostsView.as_view(), name = 'posts'),#当传递进来的路径是posts的时候,我们会用PostsView.as_view()这个函数 path('post/<int:pk>', PostDetailView.as_view(), name = 'post_detail'), #a key will be provided with the post and use it as primary key to render it. path('post/new/', PostCreateView.as_view(), name = 'make_post'), 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'), path('edit_profile/<int:pk>/', EditProfile.as_view(), name = 'edit_profile'), path('togglefollow', toggleFollow, name = 'togglefollow'), path('comment', addComment, name='addComment'), path('explore', ExploreView.as_view(), name='explore'), ]
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 #app level create a urls.py then use project-level to use app-level urls 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 # then we can use include from Insta.views import (HelloWorld, PostsView, PostDetailView, PostCreateView, PostUpdateView, PostDeleteView, addLike, UserDetailView, addComment, toggleFollow, EditProfile) urlpatterns = [ path('helloworld', HelloWorld.as_view(), name='helloworld'), #as_view funvtion是继承TemplateView #add a url posts/ path('', PostsView.as_view(), name='posts'), path('post/<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='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'), path('edit_profile/<int:pk>/', EditProfile.as_view(), name='edit_profile'), path('togglefollow', toggleFollow, name='togglefollow'), path('comment', addComment, name='addComment'), ]
"""Proj1 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 include, path from Insta.views import HelloWorld urlpatterns = [ path('', HelloWorld.as_view(), name='hello') ]