django数据库崩溃与大文本字段输入

时间:2015-06-26 01:39:47

标签: python django heroku

所以我正在编写一个基于python的django webapp并使用heroku来托管它。

我的应用程序因错误而崩溃:

Request Method: POST
Django Version: 1.8.1
Exception Type: ProgrammingError
Exception Value: autocommit cannot be used inside a transaction

我试图让用户上传一个大~10,000字符的文本文件,然后将其保存在数据库中。这是我的相关HTML:

    <form action="add_resume" enctype="multipart/form-data" method="POST">{% csrf_token %}

    E-mail:<br>
    <input type="email" name="email"><br><br>
    Upload Plain Text (.txt) Version of Resume (PDF coming soon but not now!):<br>
    <!--<input type="file" name="upload" accept="application/pdf,application/vnd.ms-excel" />-->
    <input type="file" name="resume" accept="text/plain" />
    <br><br>
    <input type="submit" value="Submit">

    </form>

这是相关的python服务器端代码:

def insert_resume(request):
    if request.method == 'GET':
        context = {'success': 'no sire'}
        return render(request, 'insert_resume.html', context)

    elif request.method == 'POST':
        email = request.POST.get("email", "")
        #resume_text = request.POST.get("resume", "")

        file = request.FILES['resume']
        resume_text = file.read()         # Reads file
        #with this line in use and the one below it commented out everything works fine
        #resume_text = "yoooo this is an awesome resume!!!"
        resume_text = str(resume_text)

        #it prints out the correct text here
        logger.info(resume_text)

        context = {'success': email}
        r = Resume(email=email, resume_text=resume_text)
        r.save()

        return render(request, 'insert_resume.html', context)

这是我的模特:

class Resume(models.Model):
    email = models.CharField(max_length=200)
    resume_text = models.TextField(blank=True, null=True)
    when = models.DateTimeField('date created', auto_now_add=True)

所以当我在那里使用硬编码的文本时,它工作正常,但我无法使用上传的文本。我记录的时候是正确的文字。我是否对模型做错了或者我是如何获取POST数据的?

谢谢!

0 个答案:

没有答案