Exemple #1
0
    https://docs.djangoproject.com/en/1.10/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
from django.contrib import admin

from blog.views import posts_list, post_detail, NewPostView, author_blog, blogs_view
from users.views import LoginView, logout

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', posts_list, name="posts_list"),
    url(r'^blogs/username/(?P<post_pk>[0-9]+)$',
        post_detail,
        name="post_detail"),
    url(r'^blogs/new-post$', NewPostView.as_view(), name="new_post"),
    url(r'^login$', LoginView.as_view(), name="login"),
    url(r'^logout$', logout, name="logout"),
    url(r'^blogs/(?P<username>[-\w]+)/$', author_blog, name="author_blog"),
    url(r'^blogs$', blogs_view, name="blogs_view")
]
Exemple #2
0
from django.urls import path, include
from rest_framework.routers import DefaultRouter

from blog.api import PostListViewSet, PostViewSet
from blog.views import HomeView, NewPostView, BlogView, PostDetailView

router = DefaultRouter()
router.register('posts', PostViewSet, basename='posts')

urlpatterns = [
    path('', HomeView.as_view(), name='home'),
    path('new-post', NewPostView.as_view(), name='new_post'),
    path('blogs/<pk>', BlogView.as_view(), name='blog'),
    path('blogs/<username>/<int:pk>', PostDetailView.as_view(), name='post_detail'),
    path('api/1.0/', include(router.urls), name='post_api'),
    path('api/1.0/blog/<int:user>/', PostListViewSet.as_view({'get': 'list'}), name='post_list_api')
]
Exemple #3
0
from django.urls import path

from blog.views import IndexView, NewCommentView, NewPostView, PostView

urlpatterns = [
    path('posts', IndexView.as_view(), name='blog-index'),
    path('posts/<int:pk>', PostView.as_view(), name='blog-post'),
    path('posts/new', NewPostView.as_view(), name='blog-new-post'),
    path('comment/new', NewCommentView.as_view(), name='blog-new-comment'),
]
Exemple #4
0
    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 django.conf.urls import url
from blog.views import (MainPageView, SignUpView, LoginView, LogoutView,
                        ProfileView, NewPostView, MyDeleteView, PostView,
                        UpdatePostView)
from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [
    path('admin/', admin.site.urls, name='admin'),
    re_path('signup', SignUpView.as_view(), name='signup'),
    re_path('login', LoginView.as_view(), name='login'),
    re_path('logout', LogoutView.as_view(), name='logout'),
    re_path('profile/', ProfileView.as_view(), name='profile'),
    re_path('newpost', NewPostView.as_view(), name='newpost'),
    re_path('posts/(?P<pid>\d+)', PostView.as_view(), name='post'),
    re_path('update_post/(?P<pk>\d+)', UpdatePostView.as_view(),
            name='update'),
    re_path(
        'delete_post/(?P<pk>\d+)', MyDeleteView.as_view(), name='delete_post'),
    url(r'^$', MainPageView.as_view(), name='index'),
    re_path('index', MainPageView.as_view()),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Exemple #5
0
from blog.api import PostListAPI, NewPostAPI, PostDetailAPI, BlogListAPI
from blog.views import post_list, user_posts, blog_list, post_detail, NewPostView
from users.api import UsersAPI, UserDetailAPI
from users.views import LoginView, logout, UserView

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', post_list, name="post_list"),
    url(r'^blogs/$', blog_list, name="blog_list"),
    url(r'^blogs/(?P<user_name>[a-zA-Z0-9]+)/$', user_posts,
        name="user_posts"),
    url(r'^blogs/(?P<user_name>[a-zA-Z0-9]+)/(?P<post_pk>[0-9]+)/$',
        post_detail,
        name="post_detail"),
    url(r'^new-post/$', NewPostView.as_view(), name="post_new"),

    #Users
    url(r'^login$', LoginView.as_view(), name="login"),
    url(r'^logout$', logout, name="logout"),
    url(r'^signup$', UserView.as_view(), name="signup"),

    #API Users. Me permiten. La primera consultar los usuarios, y la segunda ver el detalle, borrar o actualizar el usuario con ese id.
    url(r'^api/1.0/users/$', UsersAPI.as_view(), name="users_api"),
    url(r'^api/1.0/users/(?P<pk>[0-9]+)/$',
        UserDetailAPI.as_view(),
        name="user_detail"),

    #API Blogs. Endpoints para listado de blogs, leer articulos de un blog y para crear, modificar y borrar posts.
    url(r'^api/1.0/blogs/$', BlogListAPI.as_view(), name="bloglist_api"),
    url(r'^api/1.0/blogs/(?P<pk>[0-9]+)/$',
Exemple #6
0
from django.contrib import admin
from django.urls import path

from blog.views import IndexView, PostDetailView, NewPostView

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', IndexView.as_view(), name='index-view'),
    path('posts/<slug:slug>/', PostDetailView.as_view(), name='post-view'),
    path('new-post/', NewPostView.as_view(), name='new-post-view'),
]
Exemple #7
0
            return JsonResponse({'msg': '没有找到相关文章'}, status=404)

        try:
            post.title = request.POST.get('title')
            post.content = request.POST.get('content')
            post.is_top = request.POST.get('is_top') == 'true'
            post.is_reprint = request.POST.get('is_reprint') == 'true'
            post.reprint_src = request.POST.get('reprint_src')
            post.edit_time = datetime.datetime.now()

            if request.POST.get('is_publish') == 'true':
                post.status = '0'
            else:
                post.status = '1'

            post.abstract = NewPostView.markdown2text(
                post.content)[:150]  # 这个方法定义在NewPostView里了…
            post.save()

        except Exception, e:
            print traceback.format_exc(e)
            return JsonResponse({'msg': '保存失败'}, status=500)

        try:
            category = Category.objects.get(
                cate_id=request.POST.get('category'))
            tags = json.loads(request.POST.get('tag'))
            post.category = category
            for tag in post.tag.all():
                post.tag.remove(tag)
            for tag in tags:
                try:
Exemple #8
0
from django.urls import path

from blog.views import HomeView, PostDetailView, NewPostView, PostUpdate, PostDelete

app_name = 'blog'
urlpatterns = [
    path('<str:user>/', HomeView.as_view(), name='dashboard'),
    path('<str:user>/new-post/', NewPostView.as_view(), name='new-post'),
    path('<str:user>/<slug:slug>/update/',
         PostUpdate.as_view(),
         name='update-post'),
    path('<str:user>/<slug:slug>/delete/',
         PostDelete.as_view(),
         name='delete-post'),
    path('<str:user>/<slug:slug>/',
         PostDetailView.as_view(),
         name='post-detail'),
]