0

i am using slug field in my blogs. here's how i am creating slugs views.py

def Creating_blog(request):
    form=BlogForm()
    if User.is_authenticated:
        if request.method=='POST':
                form=BlogForm(request.POST,request.FILES)
                if form.is_valid:
                    blog_obj=form.save(commit=False)
                    blog_obj.author=request.user
                    title=blog_obj.blog_title
                    blog_obj.slug = title.replace(' ','-') + '-'+ str(uuid.uuid4())
                    blog_obj.save()
                    return redirect('index')
    return render(request,'blogs/creatingblog.html',context={'form':form})

Using slug to lead to the blog details page

<a href="{% url 'blog_details' slug=blog.slug %}">Read More</a>

but whenever i click on that it shows me

raise TemplateSyntaxError("Could not parse the remainder: '%s' "
django.template.exceptions.TemplateSyntaxError: Could not parse the remainder: 'slug=blog.slug' from ''blog_details'slug=blog.slug'

i have tried with slugify too

<a href="{% url 'blog_details' slug=blog.slug|slugify %}">Read More</a>

but it remains the same

help me out please.

Abu RayhaN
  • 359
  • 1
  • 3
  • 11

1 Answers1

0

As @Dev already mentions, you can simply do:

<a href="{% url 'blog_details' blog.slug %}">Read More</a>

Don't need to 'slugify' it either, as its already a slug.

Additionally, but unrelated, I'd recommend using Django's class-based views.

webtweakers
  • 715
  • 7
  • 19