本文整理汇总了Python中package.forms.PackageExampleForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python PackageExampleForm.is_valid方法的具体用法?Python PackageExampleForm.is_valid怎么用?Python PackageExampleForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类package.forms.PackageExampleForm
的用法示例。
在下文中一共展示了PackageExampleForm.is_valid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_example
# 需要导入模块: from package.forms import PackageExampleForm [as 别名]
# 或者: from package.forms.PackageExampleForm import is_valid [as 别名]
def edit_example(request, slug, id, template_name="package/edit_example.html"):
package_example = get_object_or_404(PackageExample, id=id)
form = PackageExampleForm(request.POST or None, instance=package_example)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse("package", kwargs={"slug": package_example.package.slug}))
return render(request, template_name, {"form": form, "package": package_example.package})
示例2: add_example
# 需要导入模块: from package.forms import PackageExampleForm [as 别名]
# 或者: from package.forms.PackageExampleForm import is_valid [as 别名]
def add_example(request, slug, template_name="package/add_example.html"):
package = get_object_or_404(Package, slug=slug)
new_package_example = PackageExample()
form = PackageExampleForm(request.POST or None, instance=new_package_example)
if form.is_valid():
package_example = PackageExample(package=package, title=request.POST["title"], url=request.POST["url"])
package_example.save()
return HttpResponseRedirect(reverse("package", kwargs={"slug": package_example.package.slug}))
return render(request, template_name, {"form": form, "package": package})