我收到错误,我不知道如何修复,甚至为什么我会收到错误。
我正在渲染一个表单,将一个团队链接到一个url中的项目,其中: http://127.0.0.1:8000/website/project/20/linkteam2其中20是我的pk1 = 20,这是项目ID。我正在使用pk1和pk2,因为当团队链接时,网址变为:http://127.0.0.1:8000/website/project/20/team_id
出于某种原因,我得到了:
TypeError at /website/project/21/linkteam2/
TeamSelect() got an unexpected keyword argument 'pk1'
我的代码是:
def TeamSelect(request):
import pdb; pdb.set_trace()
if request.method == "POST":
select_form = EditSelectTeam(request.user, request.POST)
if select_form.is_valid():
data = select_form.cleaned_data['team_choice']
obj2 = Project.objects.filter(project_hr_admin=request.user)
obj3 = obj2.latest('id')
if obj3.team_id == None:
obj3.team_id = data
obj3.save()
obj4 = obj3.team_id
obj5 = obj4.members.all()
for i in obj5:
current_site = get_current_site(request)
message = render_to_string('acc_join_email.html', {
'user': i.first_name,
'domain':current_site.domain,
})
mail_subject = 'You have been invited to SoftScores.com please LogIn to get access to the app'
to_email = i.email
email = EmailMessage(mail_subject, message, to=[to_email])
email.send()
messages.success(request, 'test')
return HttpResponseRedirect(reverse('website:ProjectDetails', kwargs={'pk1':obj3.id, 'pk2':obj4}))
else:
print('this project has already a team')
else:
print('Non Valid form')
else:
import pdb; pdb.set_trace()
select_form = EditSelectTeam(request.user)
return render(request,'link_project.html',
{'select_form':select_form })
我的HTML:
{% load static %}
<div class="invite-team">
<div class="jumbotron greenback">
<div class="jumbo-text">
<h7>Your project has been created, It is time to link a team or create a new for your project</h3>
</div>
<div class="jumbo-button">
<a href="{% url 'website:team_select' pk1=project.id %}" class="btn btn-secondary" role="button"><span class="fa fa-link"></span> Link an existing team</a>
<a href="{% url 'website:add_team' pk1=project.id %}" class="btn btn-success" role="button"><span class="fa fa-plus-circle"></span> Create a new team</a>
</div>
</div>
</div>
myUrl:
from django.conf.urls import url, include
from website import views
app_name = 'website'
urlpatterns = [
url(r'^hr_index/$', views.HRIndex.as_view(), name='hr_index'),
url(r'^candidate_index/$', views.CandidateIndex.as_view(),name='candidate_index'),
url(r'^employee_index/$', views.EmployeeIndex.as_view(),name='employee_index'),
url(r'^addproject/$', views.ProjectCreate.as_view(), name='add_project'),
url(r'^project/(?P<pk1>[0-9]+)/addteam/$', views.TeamCreate.as_view(), name='add_team'),
#url(r'^project/(?P<pk1>[0-9]+)/linkteam/$', views.LinkTeam.as_view(), name='link_team'),
url(r'^project/(?P<pk1>[0-9]+)/linkteam2/$', views.TeamSelect, name='team_select'),
url(r'^project/(?P<pk1>[0-9]+)/$',views.ProjectDetailView.as_view(), name='ProjectDetails'),
url(r'^project/(?P<pk1>[0-9]+)/api/chart/data2/$',views.TeamChartData.as_view(), name='TeamChartData'),
url(r'^project/(?P<pk1>[0-9]+)/(?P<pk2>[0-9]+)/$',views.EmployeeDetailView.as_view(), name='EmployeDetails'),
url(r'^project/(?P<pk1>[0-9]+)/(?P<pk2>[0-9]+)/api/chart/data/$',views.EmployeeChartData.as_view(), name='EmployeeChartData'),
#url(r'^project/(?P<pk>[0-9]+)/api/chart/data/$', views.ChartData.as_view(), name='chartdata'),
你能帮帮我吗?
答案 0 :(得分:1)
这是意料之外的,因为您没有在视图中定义参数。您的所有观点都是期望的。变化
def TeamSelect(request):
到
def TeamSelect(request, pk1=None):
为视图添加额外的参数。