Exemple #1
0
def wenzhang_xinwen_fabu(request):
    if request.session.get('username'):
        categorise = Category.objects.all()
        fobj = request.FILES.get('photo')
        path = settings.MDEIA_ROOT
        fp = FileUpload(fobj)
        path_photo = os.path.join('/static/img/' + str(fobj))
        if request.method == 'POST':
            #获取表单提交的信息
            cate = request.POST.get('cate')
            c_id = Category.objects.filter(c_name=cate).first().c_id
            a_title = request.POST.get('title')
            a_content = request.POST.get('content')
            a_time = datetime.now()

            if fp.Upload(path):
                print(path_photo)
                if a_title and a_content:
                    article = Article(a_title=a_title,
                                      a_content=a_content,
                                      a_create_time=a_time,
                                      c_id=c_id,
                                      a_picture=path_photo)
                    article.save()
    else:
        return redirect(reverse('App:login'))

    return render(request, 'wenzhang_xinwen_fabu.html', locals())
Exemple #2
0
def createarticle(request):
    if request.method == "POST":
        try:
            user_id = request.session.get("user_id")
            title = request.POST.get("title")
            article = request.POST.get("article")
            #print(user_id)
            #print(title)
            #print(article)
            articles = Article()
            articles.a_user = User.objects.get(pk=user_id)
            articles.a_title = title
            articles.a_desc = article
            articles.save()
            data = {"msg": "ok", "status": 200}
            return JsonResponse(data=data)
        except:
            data = {"msg": "error"}
            #print("error")
            return render(request, "main/mine.html")
            #return JsonResponse(data=data)
    elif request.method == "GET":

        return render(request, "main/create_article.html")