我正在嘗試創建一個網頁,您可以將問題上傳到Questions
數據庫。我想知道是否有任何簡單的方法在Django中做到這一點?我可以上傳它,以便可以從Django管理員訪問嗎?這是我的。從模板上傳到Django數據庫
#Models
class Question(models.Model):
question = models.CharField(max_length=400)
answer = models.CharField(max_length=400)
def __unicode__(self):
return self.question + "?"
class QuestionForm(ModelForm):
class Meta:
model = Question
fields = ['question', 'answer']
#Question Template
<div class="container" align="center">
<div class="hero-unit3" align="center">
<h3>
Feel free to post some questions, and a DarKnight representative will answer them for you.
</h3>
</div>
</div>
</div>
<div class="row">
<div class="span6">
<h4>
<form action="<!-- NO IDEA WHAT TO DO -->" method="post">
<input type="text" name="question" />
</div>
</div>
</div>
#views.py
class question(generic.ListView):
template_name = 'users/question.html'
context_object_name = 'Question_list'
def get_queryset(self):
return Question.objects.order_by('question')
你的視角在哪裏? –
@HieuNguyen加了我的看法 – pepper5319