示例#1
0
文件: urls.py 项目: 1615961606/haocao
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
from django.contrib import admin
from blogs.views import index, SearchView, blog_list, blog_detail, CommentView
from users.views import LoginView, RegisterView, ActiveView, LogoutView
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', index, name='index'),
    url(r'^list$', blog_list, name='blog_list'),
    url(r'^search$', SearchView.as_view(), name='search'),
    url(r'^category/(?P<cid>[0-9]+)/$', blog_list),
    url(r'^tags/(?P<tid>[0-9]+)/$', blog_list),
    url(r'^blog/(?P<bid>[0-9]+)/$', blog_detail, name='blog_detail'),
    url(r'^comment/(?P<bid>[0-9]+)$', CommentView.as_view(), name='comment'),
    url(r'^login/', LoginView.as_view(), name='login'),
    url(r'^register/', RegisterView.as_view(), name='register'),
    url(r'^active/(?P<active_code>[a-zA-Z0-9]+)',
        ActiveView.as_view(),
        name='active'),
    url(r'^logout/', LogoutView.as_view(), name='logout'),
]
示例#2
0
from django.conf.urls import url
from blogs.views import (IndexView, ArticleView, AllView, SearchView,
                         ColumnView, UserView, NewsView, TagView, CategoryView)
from django.views.generic import TemplateView, DetailView
from blogs.models import News

urlpatterns = [
    url(r'^$', IndexView.as_view(), name='index-view'),
    url(r'^article/(?P<slug>\w+)$',
        ArticleView.as_view(),
        name='article-detail-view'),
    url(r'^all/$', AllView.as_view(), name='all-view'),
    url(r'^search/$', SearchView.as_view()),
    url(r'^login/$',
        TemplateView.as_view(template_name="blog/login.html"),
        name='login-view'),
    url(r'^register/$',
        TemplateView.as_view(template_name="blog/register.html"),
        name='register-view'),
    url(r'^forgetpassword/$',
        TemplateView.as_view(template_name="blog/forgetpassword.html"),
        name='forgetpassword-view'),
    url(r'^resetpassword/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
        TemplateView.as_view(template_name="blog/resetpassword.html"),
        name='resetpassword-view'),
    url(r'^column/(?P<column>\w+)/$',
        ColumnView.as_view(),
        name='column-detail-view'),
    url(r'^user/(?P<slug>\w+)$', UserView.as_view(), name='user-view'),
    url(r'^news/$', NewsView.as_view(), name='news-view'),
    url(r'^news/(?P<pk>\w+)$',
示例#3
0
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, re_path
from blogs import views
from blogs.views import SearchView, blog_list, blog_detail, CommentView
from users.views import LoginView, RegisterView, ActiveView, LogoutView

urlpatterns = [
    path('admin/', admin.site.urls),  #找到以admin开头的页面
    path('', views.index, name='index'),
    path('search/', SearchView.as_view(), name='search'),
    path('list/', blog_list, name='blog_list'),
    re_path('category/(?P<cid>[0-9])/', blog_list,
            name='category'),  #django3.04版本正则表达式不要用path,用re_path
    re_path('tags/(?P<tid>[0-9])/', blog_list, name='tags'),
    re_path('blog/(?P<bid>[0-9])/', blog_detail, name='blog_detail'),
    re_path('comment/(?P<bid>[0-9])/', CommentView.as_view(), name='comment'),
    path('login/', LoginView.as_view(), name='login'),
    path('register/', RegisterView.as_view(), name='register'),
    re_path('active/(?P<active_code>[a-zA-Z0-9]+)',
            ActiveView.as_view(),
            name='active'),  #注意,这里一定要有‘+’,要不然返回的active_code只有一个首字母
    path('logout/', LogoutView.as_view(), name='logout'),
]