# -*- 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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。