0
데이터베이스에 데이터를 추가하려고 할 때 내가 잘못하고있는 것을 볼 수 없습니다. 제출 버튼을 누르면 데이터베이스에 아무 것도 입력되지 않습니다. Enter 키를 누를 때도 마찬가지입니다.Enter 키를 눌러 django로 데이터베이스에 데이터 추가하기
여기 내 HTML 파일입니다. 여기
<script>
$(document).keypress(function(event) {
if (event.keyCode == 13 || event.which == 13) {
alert('enter key is pressed');
event.preventDefault();
}
});
</script>
<div class="col-md-6 col-md-offset-3">
<form method="POST" action="">
<p>
{% csrf_token %}
<input type="hidden" value="{{post.id}}" />
<div class="col-xs-16" style="margin: 0; 0;padding: 3%;">
<label for="inputsm">Oracle</label>
<input class="form-control input-md" type="text" value="{{ post }}">
<input type="submit" value="Submit" style="display: none" /> {{ form.body }}
<button type="submit" value="Submit" class="btn btn-success">Submit</button>
</p>
</div>
</form>
</div>
def post_list(request):
posts = Post.objects.all()
category = Category.objects.all()
context = {
'posts':posts,
'cat':category,
}
return render(request, 'journal/post_list.html', context)
def add_post(request):
post = get_object_or_404(Post, pk=pk)
if request.method == "POST":
form = PostForm(request.POST or None)
if form.is_valid():
post = form.save(commit=False)
post.save()
return redirect('post_details', pk=post.pk)
return render(request, 'journal/post_list.html', {'post': post})
else:
form = PostForm()
context = {
"form": form,
}
return render_to_response('journal/post_list.html', context)
'포스트 = get_object_or_404 (포스트, PK = PK)을 눌렀을 때 'PK가 무엇인가, 양식을 제출하는 몇 가지 자바 스크립트를 추가하려고? 그게 어디서 온거야? – karthikr