我正在尝试让项目显示我正在添加到我的数据库中。问题是我认为我有正确的代码显示,但我不能告诉它是否添加到数据库供我检查。需要有人看看有问题的代码告诉我如何修复所以我可以显示东西或如果mabye创建功能被打破。如果我在索引中取出forloop它将显示其他html但是当forloop启动时它不会。
现在添加了user = Myblackbelt.objects.add_product(request.POST)来发送信息给帖子并且它给出了新的错误
回溯:
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ core \ handlers \ exception.py"在内心 42. response = get_response(request)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ core \ handlers \ base.py"在_get_response中 187. response = self.process_exception_by_middleware(e,request)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ core \ handlers \ base.py"在_get_response中 185. response = wrapped_callback(request,* callback_args,** callback_kwargs)
文件" C:\ Users \ dbhol \ Desktop \ upload \ blackbelttest \ apps \ blackbeltapp \ views.py"在创造 43. user = Myblackbelt.objects.add_product(request.POST)
文件" C:\ Users \ dbhol \ Desktop \ upload \ blackbelttest \ apps \ blackbeltapp \ models.py"在add_product中 7. Myblackbelt = self.create(product = postData [' product'])
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ db \ models \ manager.py"在manager_method中 85. return getattr(self.get_queryset(),name)(* args,** kwargs)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ db \ models \ query.py"在创造 399. obj.save(force_insert = True,using = self.db)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ db \ models \ base.py"在保存 796. force_update = force_update,update_fields = update_fields)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ db \ models \ base.py"在save_base中 824. updated = self._save_table(raw,cls,force_insert,force_update,using,update_fields)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ db \ models \ base.py"在_save_table中 908. result = self._do_insert(cls._base_manager,using,fields,update_pk,raw)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ db \ models \ base.py"在_do_insert中 947. using = using,raw = raw)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ db \ models \ manager.py"在manager_method中 85. return getattr(self.get_queryset(),name)(* args,** kwargs)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ db \ models \ query.py"在_insert中 1045. return query.get_compiler(using = using).execute_sql(return_id)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ db \ models \ sql \ compiler.py"在execute_sql中 1054. cursor.execute(sql,params)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ db \ backends \ utils.py"执行中 79. return super(CursorDebugWrapper,self).execute(sql,params)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ db \ backends \ utils.py"执行中 64. return self.cursor.execute(sql,params)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ db \ utils.py"在退出 94. six.reraise(dj_exc_type,dj_exc_value,traceback)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ db \ backends \ utils.py"执行中 64. return self.cursor.execute(sql,params)
文件" C:\ Users \ dbhol \ Desktop \ DojoAssignments \ Python \ myenvirnoments \ djangoENv \ lib \ site-packages \ django \ db \ backends \ sqlite3 \ base.py"执行中 337.返回Database.Cursor.execute(self,query,params)
异常类型:/ blackbelt / create中的IntegrityError 异常值:blackbeltapp_myblackbelt.creator_id可能不为NULL
new.html part that is submitting
<form class="" action="{% url 'blackbelt:create' %}" method="post">
{% csrf_token %}
<p>Product: <input type="text" name="product" value=""></p>
<input type="submit" name="" value="Create">
</form>
index.html part that is showing
<h2>Your Wish List</h2>
<table class="table">
<tr>
<th>Item</th>
<th>Added By</th>
<th>Date Added</th>
<th>Remove From Wish List</th>
<th>Delete</th>
</tr>
{% for dog in wishlist%}
<tr>
<td>{{dog.item}}</td>
<td>{{dog.name}}</td>
<td>{{dog.created_at}}</td>
<td><a href="">Show</a></td>
<td><a href="">Edit</td>
<td><form action="" method="post">{% csrf_token %}<input class="btn btn-default" type="submit" value="Remove"></form></td>
{% endfor%}
</tr>
</table>
views.py
def index(request):
context = {
'wishlist':Myblackbelt.objects.all()
}
return render(request, 'blackbeltapp/index.html', context)
def create(request):
return redirect ('blackbelt:index')
from __future__ import unicode_literals
from django.db import models
from ..logReg.models import User
class ProductManager(models.Manager):
def add_product(self, postData):
user = self.create(item = postData['product'] )
print 'dog here'
models.py
class Myblackbelt(models.Model):
item = models.CharField(max_length = 70)
dateadded=models.CharField(max_length = 10)
created_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)
loguser = models.ManyToManyField(User, related_name='loguser')
creator = models.ForeignKey(User, related_name='creator')
objects = ProductManager()
答案 0 :(得分:-1)