您好,登錄后才能下訂單哦!
# -*- 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') ##自帶的認(rèn)證
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。