简体   繁体   中英

Front-End BlogPost Form in Mezzanine

I'm trying to implement a BlogPost View to add posts in the frontend of my mezzanine project. The quick blog form that can be found here is the form I'm trying to create a view with. https://github.com/stephenmcd/mezzanine/blob/master/mezzanine/blog/forms.py

added the following line to urls.py:

url("^%sadd%s$" % _slashes, "blog_post_add", name="blog_post_add"),

added this function to views.py:

@user_passes_test(lambda u: u.is_superuser)
def blog_post_add(request):
    form = BlogPostForm(request.POST or None)
    if form.is_valid():
        BlogPost = form.save(commit=False)
        BlogPost.save()
        return redirect(BlogPost)
    return render_to_response('blog/blog_post_add.html',
                              { 'form': form },
                              context_instance=RequestContext(request))

That's all I changed in these files. https://github.com/stephenmcd/mezzanine/blob/master/mezzanine/blog/urls.py

Did I miss anything completely? I'm not receiving any errors, it's simply not working. Thanks for any help and sorry - I'm quite new to Python!

Add in your settings.py

BLOG_SLUG = "/"
APPEND_SLASH = "/"

UPDATE:

url("^add%s$" % _slashes[1], "blog_post_add", name="blog_post_add"),
//this is equivalent to url("^add/$", "blog_post_add", name="blog_post_add")

In the mezzanine implementation for slashes:

_slashes = (
    "/" if settings.BLOG_SLUG else "",
    "/" if settings.APPEND_SLASH else "",
)

if BLOG_SLUG is True and not EMPTY then it is equivalent to "/", the same also in APPEND_SLASH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM