Reverse for 'add_po...
 
Notifications
Clear all

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

7 Posts
2 Users
0 Reactions
15 Views
0
Topic starter

Sir, I tried my best to debug the bug mentioned above but failed. 

forms.py

```

class BlogPostForm(forms.ModelForm):

    class Meta:
        model = Blog
        fields = ('title', 'category', 'featured_image', 'short_description', 'blog_body', 'blog_body', 'status', 'is_featured')
```
urls.py 
```
  path('posts/add/', views.add_post, name='add_post'),
```
views.py
```
def add_post(request):
    form=BlogPostForm()
    context={
        'form': form
    }
    return render(request, 'dashboard/add_post.html', context)
```
add_post.html
```
<form action= "{% url 'add_post'%}" method = "POST" style="width: 500px;">
```
posts.html
,,,
<h3>All Posts</h3>
      <a href="{% url 'add_post' %}" class="btn btn-dark text-light float-right mb-2"> Add New </a>
      <table class="table table-hover">
        <thead>
          <tr>
            <th>#</th>
            <th>Title</th>
            <th>Category</th>
            <th>Auther</th>
            <th>Featured</th>
            <th>Status</th>
          </tr>
        </thead>
        <tbody>
        {% for post in posts %}
          <tr>
            <td>{{forloop.counter}}</td>
            <td>{{ post.title }}</td>
            <td>{{ post.category }}</td>
            <td>{{ post.auther }}</td>
            <td>{{post.status}}</td>
            <td>{{ post.is_featured }}</td>
            <td>
              <a href=""><i class="fa fa-edit text-success"></i></a>
              &nbsp;
              <a href=""><i class="fa fa-trash text-danger"></i></a>
              &nbsp;
            </td>
        </tr>
        {% endfor %}
,,,
 
 
3 Answers
0

Hi Ejaz Ali Inayat, 

The issue you are facing, where the add_post URL is not found, can occur for several common reasons:

  1. Verify that your app is listed in INSTALLED_APPS in settings.py.

  2. Ensure that the app’s urls.py file is included in the main urls.py file.

  3. Double-check for any spelling mistakes in the URL you are trying to access.

Please review these points. If you are still unable to fix the issue, kindly share your updated GitHub repository with us so we can assist you further in resolving the issue.

Ejaz Ali Inayat Ejaz Ali Inayat Topic starter 01/02/2025 12:11 am

@mohaiminul-islam Sir, I Tried my best but all in vain. My git repository link is as
https://github.com/webextolcollege/django-blog.git

0

Hi Ejaz Ali Inayat, 

I checked your code in your GitHub repository and noticed that you haven't defined the add_post URL in the dashboard/urls.py file. Additionally, your add_post function is incomplete.

Please add the add_post URL in dashboard/urls.py and complete the add_post function. If you have already made these changes but haven't pushed the code to GitHub, please push the updated code and let me know.

Ejaz Ali Inayat Ejaz Ali Inayat Topic starter 02/02/2025 9:28 pm

@mohaiminul-islam Sir Need Your Special Kind Cooperation to solve the issue " Reverse for 'add_post' not found. 'add_post' is not a valid view function or pattern name." All requisite files code pasted above

https://github.com/webextolcollege/django-blog.git

0

Hi Ejaz Ali Inayat, 

As I mentioned earlier, the issue you are facing is due to the absence of a defined URL for add_post in the urls.py file of the dashboard app. Additionally, I could not find any related code on your GitHub repository. I have fixed this issue and attached the updated file below. Please review it.

Also, you can refer to our official GitHub repository:
GitHub Repository

Ejaz Ali Inayat Ejaz Ali Inayat Topic starter 04/02/2025 12:38 am

@mohaiminul-islam Issue solved, A bundle of thanks, Sir,

IMG 1866 rathank.com Mohaiminul - Team Rathan 04/02/2025 10:28 am

Ejaz Ali Inayat , you're most welcome

Share: