您好,登錄后才能下訂單哦!
# -*- coding: utf-8 -*- from django.shortcuts import render # Create your views here. from django.shortcuts import render,HttpResponse,HttpResponseRedirect import models from django.http import Http404 from django.core.exceptions import ObjectDoesNotExist import utils import json from django.contrib.auth import authenticate,login,logout from django.contrib.auth.decorators import login_required from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger # Create your views here. def account_login(request): if request.method == 'GET' : return render(request,'login.html') else: print request.POST username = request.POST.get('username') passwd = request.POST.get('password') user = authenticate(username=username,password=passwd) if user is not None: login(request,user) user.userprofile.online = True user.userprofile.save() return HttpResponseRedirect("/") else: return render(request,'login.html',{ 'login_err': "Wrong username or password!" }) def index(request): articles_list = models.Article.objects.all().order_by('-publish_date') paginator = Paginator(articles_list, 2) # Show 25 contacts per page page = request.GET.get('page') try: articles = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. articles = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. articles = paginator.page(paginator.num_pages) return render(request,'index.html',{ 'articles': articles }) def article(request,article_id): err_msg = [] try: article_obj = models.Article.objects.get(id=article_id) comments =utils.build_comments_tree(request) #comments =utils.build_comments_tree(request,article_obj) except ObjectDoesNotExist,e: err_msg =str(e) return render(request,'aritcle.html',{ 'article': article_obj, 'comments':comments, 'err_msg': err_msg }) def create_article(request): if request.method == "GET" : return render(request,'create_aritcle.html') elif request.method == "POST" : print request.POST print request.FILES ##查看上傳圖片的路徑 bbs_generater = utils.ArticleGen(request) res = bbs_generater.create() html_ele =""" Your article <<a href="/article/%s/"> %s</a>> has been created successfully !!!, """ %(res.id, res.title) return HttpResponse(html_ele) def life(request): return render(request,'life.html') def tech(request): return render(request,'tech.html') def category1024(request): return render(request,'1024.html') ##自帶的認證
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。