擅长:python、mysql、java
<pre class="lang-py prettyprint-override"><code>@login_required
def hero_detail_create_view(request):
# creating by form
form = HeroCreateModelForm(request.POST or None)
if form.is_valid():
obj = form.save(commit=False)
slugCreate = str.lower(form.cleaned_data.get("name") + "-" + form.cleaned_data.get('nickname'))
obj.slug = slugCreate.replace(" ","")
obj.user = request.user
obj.save()
return redirect("home.html")
template_name="form.html"
context = {"form":form}
return render(request, template_name, context)
</code></pre>