Эта ошибка возникает, когда я пытаюсь вызвать другую страницу для редактирования информации о главной странице службы.
TypeError в / servicesurvey / 8: pk edit_survey () получил неожиданный аргумент ключевого слова int метод запроса: GET URL запроса: http://localhost:8080/servicesurvey/8:pk Версия Django: 2.0 Тип исключения: TypeError Значение исключения:
edit_survey () получил неожиданный аргумент ключевого слова 'int'
домашняя страница
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- /Css -->
<link rel = "stylesheet"
type = "text/css"
href = "../static/survey.css" />
<!-- /Css -->
<title>Delta</title>
<!-- /Fonts -->
<link href='https://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet'>
<link href="https://fonts.googleapis.com/css?family=Poppins:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900" rel="stylesheet">
<!-- /Fonts -->
</head>
<body>
<div>
<div class="absolute">
<h1 id="home_name">Delta</h1>
</div>
<div id="Delta" class="logoPrincipal">
<img src="../static/logo.png" alt="Delta">
</div>
<div>
<ul class="nav">
<li>
<a href="{% url 'qrcode' %}">
<img src="../static/images.png" alt="Leia o QR Code com seu celular">
</a>
</li>
<li>
<a href="{% url 'servicesurvey' %}">
<img src="../static/form.png" alt="Leia o QR Code com seu celular">
</a>
</li>
</ul>
</div>
<div>
<section>
<p>teste123...</p>
</section>
</div>
<div>
<section>
<p>teste123...</p>
</section>
</div>
</div>
</body>
</html>
страница редактирования
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>Editar Pesquisa</h1>
<form class="formSurvey" action="{% url 'edit_survey' survey.id %}" method="post">
{% csrf_token %}
{{ surveyform }}
<div class="row">
<input type="submit" value="Editar">
</div>
</form>
</body>
</html>
url.py
from django.contrib import admin
from django.urls import path
from survey import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home, name='home'),
path('servicesurvey', views.servicesurvey, name='servicesurvey'),
path('qrcode', views.qrcode, name='qrcode'),
path('index', views.index, name='index'),
path('servicesurvey/<int>:pk', views.edit_survey, name='edit_survey'),
]
view.py
from django.shortcuts import render
from .forms import SurveyForm
from .models import Survey
def home(request):
return render(request, 'survey/home.html')
def index(request):
return render(request, 'survey/index.html')
def servicesurvey(request):
if request.method == 'POST':
filled_form = SurveyForm(request.POST)
if filled_form.is_valid():
created_survey = filled_form.save()
created_survey_pk = created_survey.id
note = 'Obrigado por responder nossa pesquisa'
new_form = SurveyForm()
return render(request, 'survey/servicesurvey.html', {'created_survey_pk': created_survey_pk, 'surveyform': new_form, 'note':note})
else:
form = SurveyForm()
return render(request, 'survey/servicesurvey.html', {'surveyform':form})
def qrcode(request):
return render(request, 'survey/qrcode.html')
def edit_survey(request, pk):
survey = Survey.objects.get(pk=pk)
form = SurveyForm(instance=survey)
if request.method == 'POST':
filled_form = SurveyForm(request.POST, instance=survey)
if filled_form.is_valid():
filled_form.save()
form = filled_form
return render(request, 'survey/edit_survey.html', {'surveyform': form, 'survey': survey})