def scraper(request, projectname):
try:
project = Project.objects.get(user=request.user, project_name=projectname)
except Project.DoesNotExist:
return HttpResponseNotFound('Nothing is here.')
spiderclassnamelabel = "class " + request.user.username.title() + project.project_name.title() + "Spider:"
if request.method == 'GET':
form = Scraper(initial={'function': project.scraper_function})
form.fields['function'].label = spiderclassnamelabel
return render(request, 'addscraper.html', {'username': request.user.username, 'form': form, 'project': project.project_name})
elif request.method == 'POST':
if 'cancel' in request.POST:
return HttpResponseRedirect(reverse("manageproject", args=(projectname,)))
if 'submit' in request.POST:
form = Scraper(request.POST)
form.fields['function'].label = spiderclassnamelabel
if form.is_valid():
project.scraper_function = form.cleaned_data['function']
project.save()
return HttpResponseRedirect(reverse("manageproject", args=(projectname,)))
else:
return render(request, 'addscraper.html',
{'username': request.user.username, 'form': form, 'project': project.project_name})
views.py 文件源码
python
阅读 20
收藏 0
点赞 0
评论 0
评论列表
文章目录