Answer the question
In order to leave comments, you need to log in
When forming a link to an article, %2F appears at the beginning of the path. Why and how to remove
Here is my "urls.py":
from django.urls import path
from . import views
app_name = 'News'
urlpatterns = [
path('', views.mainS, name = 'mainS'),
path('/<int:articleId>-<slug:articleSlug>/', views.article_details, name = 'article_details'),
]
from django.shortcuts import render
from .models import Article
def mainS(request):
articles = Article.objects.order_by("article_datePub")[:10]
return render(request, "News/News.html", {"articles": articles})
def article_details(request, articleId, articleSlug):
return render(request, "News/article_details.html")
{% block main_block %}
<div class="block-main center-block-main clearfix">
{% for article in articles %}
<div class="block-new">
<a href="{% url 'News:article_details' article.id article.article_slug %}"><div class="new">
<img src="{{ MEDIA_URL }}{{ article.article_img.url }}" alt="">
<div class="text-new">
<div class="text-newh1">
<h1 class="texth1">{{ article.article_title }}</h1>
</div>
<div class="text-newp">
{{ article.article_text }}
</div>
</div>
</div></a>
</div>
{% endfor %}
</div>
{% endblock main_block %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question