I get this error when trying to use the template that should link to the edit page.
I have seen someone do this using UpdateView but it gives the same error when i try it
here is some more relevant info
SO says i need to add more text so here is some more text (ignore this): more text more more text
templates:
{% block content %}
<div class="content_section">
<div class="btn_container">
<a class="new_post" href="{% url 'newpost' %}"><button class="new_post_btn">New Post</button></a>
</div>
<div class="content_section_two">
{% for product in products %}
<div class="post_short_container">
<div class="title_container">
<a href="#" class="post_link">
<div><b>{{ product.title }}</b></div>
</a>
</div>
<div class="right_btns">
<a href="{% url 'editpost' post.id %}" class="edit_link">Edit</a>
<a href="#" class="stats_link">Stats</a>
<div class="ad_btn_container">
<div class="ad_btn">Ad</div>
</div>
<div class="delete_btn_container">
<div class="delete_btn">Delete</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock content %}
urls.py:
urlpatterns = [
path('editpost/<int:pk>/', views.editPost, name='editpost'),
]
views.py
def editPost(request, pk):
post = Post.objects.get(id=pk)
form = NewPost(instance=post)
if request.method == 'POST':
form = NewPost(request.POST, request.FILES, instance=post)
if form.is_valid():
form.save()
return redirect('myposts')
return render(request, 'create/new_post.html', {'form': form})
ListView:
def myPosts(request):
context = {
'products': Post.objects.all()
}
return render(request, 'create/my_posts.html', context)
class PostListView(ListView):
model = Post
template_name = 'my_posts.html'
context_object_name = 'products'
question from:
https://stackoverflow.com/questions/65545410/django-error-reverse-for-editpost-with-arguments-not-found-1-pattern 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…