views.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:Distributed-Multi-User-Scrapy-System-with-a-Web-UI 作者: aaldaber 项目源码 文件源码
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})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号