bbs视图views.py-创新互联
# -*- 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 < %s> 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') ##自带的认证目前创新互联公司已为上1000+的企业提供了网站建设、域名、网页空间、网站托管维护、企业网站设计、东湖网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
本文标题:bbs视图views.py-创新互联
网站链接:http://ybzwz.com/article/ddcoji.html