请事先原谅我-我知道有一些问题-但我真的没有找到解决办法。在
我在Django上工作,我想填充一个Postgresql表,这个表是由我创建的模型创建的。
我还创建了我的表单、html页面(模板)和视图。我没有错误消息,但是数据库中没有创建任何内容。在
这是我的模型.py在
class ModForm1(models.Model) :
utilisateur = models.CharField(max_length=100)
description = models.CharField(max_length=500)
date = models.DateTimeField(auto_now_add=True, auto_now=False,
verbose_name="Date de parution")
def __unicode__(self):
return "{0} {1} {2} {3} ".format(self, self.utilisateur, self.description, self.date)
这是我的表单.py在
^{pr2}$这是我的模板:
<div class="container">
<div style="width:30%">
<form role="form" action="." method="post">
<div class="col-xs-12">
<legend><i class="icon-group"></i> Authentification</legend>
{% csrf_token %}
<div class="form-group">
<label for="example-text-input">Utilisateur</label> {{ form.utilisateur }}
</div>
<div class="form-group">
<label for="example-text-input">Description</label> {{ form.description }}
</div>
<input class="btn btn-primary" type="submit" value="submit" />
</form>
</div>
</div>
这是我的视图.py在
def addentry(request):
form = ModForm1Form(request.POST)
# if this is a POST request we need to process the form data
if request.method == 'POST':
if form.is_valid():
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
form.save()
return HttpResponseRedirect('.')
#messages.error(request, "Error")
# if a GET (or any other method) we'll create a blank form
else:
messages.error(request, "Error")
return render(request, 'addentry.html', {'form': form})
我读了StackOverflow中几乎所有的问题,但我真的被卡住了。我真的不明白为什么什么都没写进我的数据库。
你能帮我看看吗?在
谢谢!
朱利安
编辑-数据库配置设置.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django',
# The following settings are not used with sqlite3:
'USER': 'julien',
'PASSWORD': '***',
'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '5432',
}
}
您想使用mysql数据库,但是在
settings.py
中设置了'ENGINE': 'django.db.backends.postgresql_psycopg2'
这个设置是针对PostgreSQL的,而不是针对mysql的。必须将此字符串更改为以下内容:'ENGINE': 'django.db.backends.mysql'
。在希望这是帮助。在
相关问题 更多 >
编程相关推荐