我为我的大学建立了一个常规的django网站,该网站允许用户登录,注销并上载便笺(文档),然后可以将其下载。
我已经在heroku免费套餐上部署了django应用。 一切正常,直到用户登录并尝试上传文档。该网站已部署here。请随时使用该应用程序并上传测试文档并解决该问题。我曾尝试过调试,但不幸的是没有运气。
这是我认为引起问题的TL; DR代码。 源代码为github
# models.py
class Notes_Model(models.Model):
uploader = models.CharField(max_length=200)
title = models.CharField(max_length=200)
date_posted = models.DateTimeField(auto_now_add=True)
description = models.TextField(max_length=2500)
branch_choice = models.CharField(max_length=50, choices=branch_choices, default='cse')
file_semester = models.CharField(choices=semester_choice, max_length=2)
file = models.FileField()
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse("notes-detail", kwargs={"pk": self.pk})
# views.py
class PostCreateView(LoginRequiredMixin, CreateView):
"""
Lets user upload files under the UPLOAD navigation button
"""
model = Notes_Model
fields = ['title', 'description', 'file_semester', 'branch_choice', 'file']
@login_required
def upload_file(self, request):
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
form.save()
messages.success(request, f'Your files have been uploaded')
return redirect('notes-home')
def form_valid(self, form):
form.instance.uploader = self.request.user
# form.save()
return super(PostCreateView, self).form_valid(form)
# settings.py
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "dbnrxxxxxx",
"USER": "nyppmrxxxxxxxx",
"PASSWORD": "a very long string",
"HOST": "xxx-xx.xxx.compute-1.amazonaws.com",
"PORT": "5432",
}
}
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=600)
DATABASES['default'].update(db_from_env)
上载文档时出现错误
DataError at /notes/new/
invalid input syntax for integer: "Computer Science Engineering"
LINE 1: ...1-28T01:18:45.282746+00:00'::timestamptz, 'test', 'Computer ...
^
Request Method: POST
Request URL: https://medinotesdev.herokuapp.com/notes/new/
Django Version: 2.2.1
Exception Type: DataError
Exception Value:
invalid input syntax for integer: "Computer Science Engineering"
LINE 1: ...1-28T01:18:45.282746+00:00'::timestamptz, 'test', 'Computer ...
^
Exception Location: /app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py in _execute, line 84
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.6.10
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python36.zip',
'/app/.heroku/python/lib/python3.6',
'/app/.heroku/python/lib/python3.6/lib-dynload',
'/app/.heroku/python/lib/python3.6/site-packages']
Server time: Tue, 28 Jan 2020 01:18:45 +0000