3 페이지를 갖고 싶습니다. 하나는 특정 디렉토리의 특정 사용자 이름을 "정적"이라고 표시합니다 (내 views.py에서 볼 수 있습니다). 사용자가 사용자를 추가하려면 2 개의 "추가"버튼 중 하나를 누릅니다. 사용자가 사용자 이름과 비밀번호를 입력 할 수있는 두 번째 페이지로 이동하면 "제출 "버튼을 누릅니다. 그런 다음 데이터를 "정적"폴더에 저장해야합니다. 그 후 그는 "등록 성공"이라고 말한 다른 사이트로 이동하고 3 초 후 index.html로 돌아가 결과를 확인합니다. 첫 번째 웹 사이트에 대한 템플릿 :어떻게 장고에서 데이터를 제출할 수 있습니까?
<head>
{% block title %}
<h3>
Following users exist in the folder 'static' :
</h3>
{% endblock %}
</head>
<body>
<table border = "0" width = "100%" align = "left">
<tr>
<td align = "right">
<form action = "adduser.html" method = "post">{% csrf_token %}
<input type = "submit" name = "form" style = "width:8%" value = "Add">
</td>
</tr>
{% for file in files %}
<tr>
<td align = "left"> {{ file }} </td>
</tr>
{% endfor %}
<tr>
<td align = "right">
<form action = "adduser.html" method = "post">{% csrf_token %}
<input type = "submit" name = "form" style = "width:8%" value = "Add">
</form>
</td>
</tr>
</table>
</body>
그리고 이것은 내 두 번째 웹 사이트의 템플릿입니다 :
<head>
{% block title %}
<h2 align = "middle" >
<u>Add a user</u>
</h2>
{% endblock %}
</head>
<body>
<table border = "0" width = "100%">
<tr>
<td>
<p>Username:</p>
<input type = "text" name = "" value = "" />
</td>
</tr>
<tr>
<td>
<p>Password:</p>
<input type = "password" name = "" value = "" />
</td>
</tr>
<tr>
<td>
<form action = {% url 'sslcert:redirect' %} method = "post"> {%csrf_token %}
<input type = "submit" value = "Submit">
</form>
</td>
</tr>
</table>
</body>
그리고 이것은 t의 템플릿입니다 그는 사이트를 리디렉션 :
try:
selected_choice = p.choice_set.get(pk=request.POST['choice'])
하지만 난 정말 '돈 :
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from polls.models import Choice, Question
# ...
def vote(request, question_id):
p = get_object_or_404(Question, pk=question_id)
try:
selected_choice = p.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
# Redisplay the question voting form.
return render(request, 'polls/detail.html', {
'question': p,
'error_message': "You didn't select a choice.",
})
else:
selected_choice.votes += 1
selected_choice.save()
# Always return an HttpResponseRedirect after successfully dealing
# with POST data. This prevents data from being posted twice if a
# user hits the Back button.
return HttpResponseRedirect(reverse('polls:results', args=(p.id,)))
내가이 줄은 도움이 될 수 있다고 생각 : 나는 문서를 읽고 나는이 코드 예제를 발견
<head>
<meta http-equiv = "refresh" content = "3; URL=http://10.0.3.79:8000/sslcert/">
{% block title %}
<h4>
Registration successful !
</h4>
{% endblock %}
</head>
이 프로젝트를 내 프로젝트에 할당하는 방법을 알았습니다./이미 "Username"과 "Password"라는 이름으로 모델에 2 개의 클래스를 만들었습니다. 사람은
도움이 많이 감사합니다 :(저를 도와주세요 :
잘 그래 나는 문서에보고를했다 및 I post 메서드로 시도해 보았지만 분명히 작동하지 않았고 실제로 어떻게해야할지 모르겠다. / –