Reverse for 'login' not found. 'login' is not a valid view function or pattern name.

This has nothing to do with your render statement itself. It’s an issue of what you’re rendering.

We need to see the template being rendered.

Also, when you’re posting code, please enclose it between lines consisting of three backtick - ` characters. This means you’ll have one line of ```, then your code, then another line of ```. This allows the forum to properly format your code and prevents special characters from being replaced.

KenWhitesell thank you so much …
‵‵‵Thank you KenWhitesell for your advice, I get it, it’s solved.‵‵‵

sir i’m getting this error as Reverse for ‘restaurant_page_for_order’ not found. ‘restaurant_page_for_order’ is not a valid view function or pattern name
here is my urls
urlpatterns = [
path(‘admin/’, admin.site.urls),
path(’’,include(‘app.urls’)),
]+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

my app.urls

please help me sir

my app.urls
urlpatterns = [
path(‘login’, login, name=‘login’),
path(‘logout’, logout, name=‘logout’),
path(‘signup’, signup, name=‘signup’),
path(’’, home, name=‘home’),
path(‘rest_for_order/str:slug’, rest_for_order, name=‘rest_for_order’),
path(‘cart/str:slug’, cart, name=‘cart’),
path(‘myorders’,myorders,name=‘myorders’),
path(‘savedetails’, savedetails, name=‘savedetails’),
]

When you post code here, please enclose it between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This directs the forum software to keep your code formatted properly.

Assuming that this isn’t an issue caused by your code being mangled by the forum software, the issue is that you have a url named ‘rest_for_order’, not ‘restaurant_page_for_order’.

1 Like

sir i’m getting this error as Reverse for ‘rest_for_order’ with no arguments not found. 1 pattern(s) tried: [‘rest_for_order/(?P[^/]+)$’]
here is my urls’’’
urlpatterns = [
path(‘admin/’, admin.site.urls),
path(’’,include(‘app.urls’)),
]+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
‘’’
my app.urls
path(‘home_for_order’, home_for_order, name=‘home_for_order’),
path(‘rest_for_order/str:slug’, rest_for_order, name=‘rest_for_order’),
path(‘cart/str:slug’, cart, name=‘cart’),
path(‘myorders’,myorders,name=‘myorders’),
path(‘savedetails’, savedetails, name=‘savedetails’),

please help me sir

Thank you very much… Solved my problem and gained new knowledge

sir i am getting this error!

project URL:
‘’’ path (‘membership’,include(membership.urls,namespace = ‘membership’)),

app.url:
path(’ ', MembershipSelectView.as_view(), name= ‘select’)

can you tell me what the issue with it

Sure!

First things first. Using 3 backticks characters(these: `) around code blocks makes formatting nicer. So, to your question:

path (‘membership’,include(membership.urls,namespace = ‘membership’)),

app.url:
path(’ ', MembershipSelectView.as_view(), name= ‘select’)

This only tells us what the url configuration is. We’d need to see the template that is raising the exception. Can you post that here, please?

-Jorge

@jlgimeno how can i solve this error.

Reverse for 'blogdetail' with no arguments not found. 1 pattern(s) tried: ['blogdetail/(?P<slug>[^/]+)/$']

Here is the app URLs.

urlpatterns = [
    path("blog", blog, name="blog"),
    path("blogdetail/<slug>/", blogdetail, name="blogdetail")
]

Here is the project URLs

urlpatterns = [
    path('admin/', admin.site.urls),
    path("", include("bonnie.urls")),
    path("", include("Blog.urls"))
]

Here is the template

<!-- Blog Item -->
            {% for blog in blogs %}
            <div class="blog-item padd-15">
                <div class="blog-item__inner">
                    <div class="blog-item__inner__img">
                        <img src="/media/{{blog.image}}" alt="">
                    </div>
                    <div class="blog-item__inner__info">
                        <h4 class="blog-title">{{blog.title}}</h4>
                        <span>{{blog.created_at}}</span>
                        <p class="blog-desc">{{blog.content | safe}}</p>
                        <p class="blog-tags">
                            <a href="{% url 'blogdetail' blog.slug %}" class="btn">
                                Read More
                            </a>
                        </p>
                    </div>
                </div>
            </div>
            {% endfor %}
            <!-- Blog Item End -->

The most likely cause of this error:

With a URL defined like this:

Is that at this line:

blog.slug is either null or blank. It’s finding the url named blogdetail, but that url requires an argument passed to it. Your template has such an argument defined (blog.slug), but if it’s null or a zero-length string (""), it doesn’t pass the test of being a <slug>.

1 Like

Funny thing is that it works on Django version 3.2.4 but on Django version 3.2.5 it throws that error.

How can I solve it?

It’s not a problem with the code - it’s the data. One of your blog objects doesn’t have a valid slug.

Can you please show us the blogdetail view code?

Here is the blogdetail view code

def blogdetail(request, slug):
   context = {}
   try:
      blog_obj = BlogModel.objects.filter(slug = slug).first()
      context['blog_obj'] = blog_obj
   except Exception as e:
      print(e)

   return render (request, "blogBody.html", context)

Hmm. I see a context['blog_obj'] = blog_obj in the view, but I see the variable being looped over as blogs. I agree with Ken, it looks like blog.slug doesn’t exist and that’s the cause of this.

-Jorge

Blogs is coming from the blog view.

def blog(request):
   context = {
      'blogs' : BlogModel.objects.order_by('-created_at')
   }

   return render (request, "blog.html", context)

I have deleted data in the database and added new data but still throws the error.

What would you suggest me to do?

Please post your Blog object (the definition for it in your models.py file). Is the slug attribute a field in the object, or is it a method?

If it’s a field in the object, from the shell you can do something like:
[(b.id, b.slug) for b in Blog.objects.all()]
to see the primary key and slug fields for every Blog object to ensure none of them are blank.

If slug is a model method, you would do something like this:
[(b.id, b.slug()) for b in Blog.objects.all()]

Here is the model

class BlogModel(models.Model):
    title = models.CharField(max_length=1000)
    content = FroalaField()
    slug = models.SlugField(max_length=1000, null=True, blank=True)
    user = models.ForeignKey(to=settings.AUTH_USER_MODEL, blank=True , null=True , on_delete=models.CASCADE)
    image = models.ImageField(upload_to='blog')
    created_at = models.DateTimeField(auto_now_add=True)
    upload_to = models.DateTimeField(auto_now=True) 

    def __str__(self):
        return self.title

    def save(self , *args, **kwargs):
        self.slug = generate_slug(self.title)
        super(BlogModel, self).save(*args, **kwargs)