мой английский sh знание настолько плохое, но я могу понять. когда я нажимаю кнопку отправки, появляется эта ошибка. Я использую браузер python 3. и chrome. а также, пожалуйста, помогите мне .. 4 дня я пробовал эту проблему. я думаю, что http://127.0.0.1: 8000 / product / 17 / product / addcomment / 17 эта строка дважды добавляет / product / 17 / part. почему это добавить, пожалуйста, помогите мне ?? кнопка отправки ошибка
product / urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('addcomment/', views.addcomment, name='addcomment')
]
product / views.py
def addcomment(request):
url = request.META.get('HTTP_REFERER')
if request.method == 'POST': # check post
form = CommentForm(request.POST)
if form.is_valid():
data = Comment() # create relation withmodel
data.comment = form.cleaned_data['comment']
data.subject = form.cleaned_data['subject']
data.ip = request.META.get('REMOTE_ADDR')
data.product_id = id
current_user = request.user
data.user_id = current_user.id
data.save() # save data to table
messages.success(request, 'Your Review Has be Send. Thank you for Your Review')
return HttpResponseRedirect(url)
return HttpResponseRedirect(url)
главная /urls.py
from home import views
urlpatterns = [
path('admin/', admin.site.urls),
path('home/', include('home.urls')),
path('about/', views.aboutus, name='aboutus'),
path('contact/', views.contact, name='contact'),
path('home/', include('home.urls')),
path('product/', include('product.urls')),
path('', include('home.urls')),
path('ckeditor/', include('ckeditor_uploader.urls')),
path('category/<int:id>/<slug:slug>', views.category_products, name='category_products'),
path('search/',views.search,name='search'),
path('search_auto/',views.search_auto,name='search_auto'),
path('product/<int:id>/<slug:slug>', views.product_details, name='product_details'),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
product / models.py
class Comment(models.Model):
STATUS = (
('True', 'True'),
('False', 'False'),
('New', 'New')
)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
subject = models.CharField(max_length=50, blank=True)
comment = models.CharField(max_length=250, blank=True)
ip = models.CharField(max_length=20, blank=True)
rate = models.IntegerField(default=1)
status = models.CharField(max_length=10, choices=STATUS, default='New')
create_at = models.DateTimeField(auto_now_add=True)
update_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.subject
class CommentForm(ModelForm):
class Meta:
model = Comment
fields = ['subject', 'comment', 'rate']
html файл
<form class="review-form" action="product/addcomment/{{ product.id }}" method="post">
{% csrf_token %}
<div class="form-group">
<input name="subject" class="input" type="text" placeholder="Your Subject" />
</div>
<div class="form-group">
<textarea name="comment" class="input" placeholder="Your review"></textarea>
</div>
<div class="form-group">
<div class="input-rating">
<strong class="text-uppercase">Your Rating: </strong>
<div class="stars">
<input type="radio" id="star5" name="rate" value="5" /><label for="star5"></label>
<input type="radio" id="star4" name="rate" value="4" /><label for="star4"></label>
<input type="radio" id="star3" name="rate" value="3" /><label for="star3"></label>
<input type="radio" id="star2" name="rate" value="2" /><label for="star2"></label>
<input type="radio" id="star1" name="rate" value="1" /><label for="star1"></label>
</div>
</div>
</div>
{% if user.id is not None %}
<button class="primary-btn">Submit</button>
{% else%}
First you need to Login
{% endif%}
</form>