我有一个网页,用户可以从模型中选择一个对象。基于单击的按钮,将执行某些操作。其中一项操作是调用其中一个视图,然后展开另一个网页。
因此,当用户访问http://127.0.0.1:8000/clinic/manage时,他会看到以下形式:
代码:
@login_required
def manage_clinics(request):
msg = ''
if request.method == 'POST':
clid = int(request.POST.get('clinics'))
print("POST details", request.POST)
if request.POST.get('createdoctor')=='Create Doctor':
clinicobj = Clinic.objects.get(clinicid=clid)
print("Creating Doctor for clinic:", clinicobj)
createdoctor(request, clinicobj.label)
else:
form = ChooseClinicMetaForm()
return render(request, 'clinic/manageclinics.html', {'form': form, 'msg': msg})
如果他单击“创建医生”,将执行以下查看功能:
@login_required
def createdoctor(request, cliniclabel):
msg =''
cliniclink = '/clinic/'+cliniclabel+'/createdoctor'
cl = Clinic.objects.get(label=cliniclabel)
if request.method == 'POST':
print("POST details", request.POST)
form = DoctorMetaForm(request.POST)
if form.is_valid():
print("Form is valid.")
# form.save()
username = request.POST.get('username')
name = request.POST.get('name')
email = request.POST.get('email')
phone = request.POST.get('phone')
msg = SaveDoctortoSQLNew(request)
print(msg)
if 'Error:' not in msg:
doctorobj = doctor.objects.get(name=name, email=email, phone=phone, username=username)
clinicobj = Clinic.objects.get(label=cliniclabel)
permobj = ClinicPermissions(clinicid=clinicobj, doctorid=doctorobj, viewperms =1)
permobj.save()
msg = "Successfully created a doctor and assigned permissions"
else:
msg = "Invalid details."
print(msg)
else:
# cl = Clinic.objects.get(label=cliniclabel)
form = DoctorMetaForm()
return render(request, 'clinic/doctorprofile.html', {'form': form, 'rnd_num': randomnumber(), 'cliniclink': cliniclink, 'msg': msg, 'clinic':cl})
执行此操作时,出现以下异常:
[14/Oct/2018 14:40:37] "GET /appointments/static/appointments/js/bootstrap.min.js.map HTTP/1.1" 404 1758
POST details <QueryDict: {'csrfmiddlewaretoken': ['3Jt28ToKqHiP6rGaTmbOOZH0yNRaU1TCOx427C6sV42VCbFrbrdJVlpzaSQiI3EK'], 'clinics': ['1'], 'createdoctor': ['Create Doctor']}>
Creating Doctor for clinic: Dr Joel's ENT Clinic
POST details <QueryDict: {'csrfmiddlewaretoken': ['3Jt28ToKqHiP6rGaTmbOOZH0yNRaU1TCOx427C6sV42VCbFrbrdJVlpzaSQiI3EK'], 'clinics': ['1'], 'createdoctor': ['Create Doctor']}>
Invalid details.
2018-10-14 14:40:40,928 django.request ERROR Internal Server Error: /clinic/manage
Traceback (most recent call last):
File "/home/joel/.local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/joel/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 137, in _get_response
"returned None instead." % (callback.__module__, view_name)
ValueError: The view clinic.views.manage_clinics didn't return an HttpResponse object. It returned None instead.
这显然是因为没有返回HttpResponse对象。但是createdoctor函数是否仅返回该值?还是python抱怨正在创建的octor(request,clinicobj.label)语句的返回?我应该将其包装在HttpResponse中吗?
答案 0 :(得分:3)
您似乎忘记了在\x y -> zipWith (+) (lazy3rd x) (lazy5th y)
中添加return
manage_clinics