【发布时间】:2020-07-09 13:31:26
【问题描述】:
我需要在 django 的管理页面上查看用户的输入显示,根据我的阅读,我需要使用 list_display 但管理页面上没有任何内容。也许 views.py 中存在问题,但一切看起来都很好。 这是我的代码:
Views.py
def process_e(request):
website_name = request.POST["website_name"]
product_name = request.POST["product_name"]
phone_number = request.POST["phone_number"]
website_details = request.POST["website_details"]
website_content = request.POST["website_content"]
created_objs = Enterprise.objects.create(website_name=website_name, product_name=product_name, phone_number=phone_number, website_details=website_details, website_content=website_content)
legth_of_todos = Enterprise.objects.all().count()
created_items = Enterprise.objects.all()
if request.method == 'POST':
if request.POST.get('website_name') and request.POST.get('product_name') and request.POST.get('phone_number') and request.POST.get('website_details') and request.POST.get('website_content'):
post=Enterprise()
post.title= request.POST.get('website_name')
post.content= request.POST.get('product_name')
post.content= request.POST.get('phone_number')
post.content= request.POST.get('website_details')
post.content= request.POST.get('website_content')
post.save()
return render(request, 'enterprise.html', {"created_items":created_items})
else:
pass
else:
return render(request,'enterprise.html')
Admin.py
from django.contrib import admin
from service.models import Enterprise
class PaymentsAdmin(admin.ModelAdmin):
list_display = ('website_name', 'product_name', 'phone_number', 'website_details',
'website_content')
admin.site.register(Enterprise, PaymentsAdmin)
模型.py
from django.db import models
class Enterprise(models.Model):
website_name = models.CharField(max_length=50)
product_name = models.CharField(max_length=200)
phone_number = models.CharField(max_length=200)
website_details = models.CharField(max_length=200)
website_content = models.CharField(max_length=200)
HTML
<div class="form-group">
<label>Website name</label>
<input type="text" name="website_name" class="form-control" placeholder="First name">
</div>
<div class="form-group">
<label>Product name (if there is)</label>
<input type="text" name="product_name" class="form-control" placeholder="First name">
</div>
<div class="form-group">
<label>Phone number</label>
<input type="text" claa="phone_name" class="form-control" placeholder="First name">
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">What kind of content should your website upload?</label>
<textarea class="form-control" name="website_content" rows="3"></textarea>
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Website details</label>
<textarea class="form-control" name="website_details" rows="3"></textarea>
</div>
【问题讨论】: