Django navigation issue - django

I am writing a navigation header in django. And i am having problem navigations between urls that i created.
urls.py
url(r'^home/$', home_page, name="home_url"),
url(r'^about/$', about_page, name="about_url"),
template
<a href="home_url>Home</a>
<a href="About_url>About</a>
When I click on this i am getting something like. mysite.com/home/home_url
How should i configure it so i can navigate to the correct link?

Read Naming urls docs:
For your code:
<a href="{% url 'home_url' %}" >Home</a>
About

Related

media image is not able to display on webpage

when click on "yo" I am able to see media file but when tried to display image through the image tag it is not seen on webpage
yo
<img src="{{status.adv.url}}" width="250" height="250" alt="advertise"/>
Change this
<img src="{{status.adv.url}}" width="250" height="250" alt="advertise"/>
to
<img src="{% static status.adv.url %}" width="250" height="250" alt="advertise"/>
and include {% load static %} template tag on the top of your template(s)
Your project url.py should have these
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Documentation: Managing static files (e.g. images, JavaScript, CSS)
It was add blocker used by me. so disable your add blocker.
If you want to confirm that it is add blocker open your chrome and in console you will find this "Failed to load resource: net::ERR_BLOCKED_BY_CLIENT"

Django Error Not Found: /NONE in server log

Using Django, i am passing few list to be displayed on Index page. As such it is working, but i am getting following error in the log. I believe it is an issue but can't find the rootcause. Can someone please help? I have provided required codes i am using ..
18/Jun/2020 20:30:03] "GET / HTTP/1.1" 200 24496
Not Found: /NONE
[18/Jun/2020 20:30:03] "GET /NONE HTTP/1.1" 404 2180
app Views.py
def index(request):
########
ndtvlist = "a list"
toilist = "a list"
context={'ndtvlist':ndtvlist,'toilist':toilist}
return render(request,'news/index.html', context)
proj Urls.py
path('',views.index,name='index'),
path('news/',include('news.urls')),
path('admin/', admin.site.urls),
App urls.py
path('',views.index,name='index'),
path('market/',views.market,name='market'),
path('world/',views.world,name='world'),
<nav class="navbar navbar-expand-lg bg-light techfont">
<div class="container">
<div class="navbar-nav align-items-center">
<a class="navbar-brand bigbrand" href="{% url 'index' %}">TopNews</a>
<a class="nav-item nav-link" href="{% url 'news:market' %}">Market</a>
<a class="nav-item nav-link" href="{% url 'news:world' %}">World</a>
</div>
</div>
</nav>
I tried a lot to solve the problem, i spot a way to trigger it, it happen everytime an url has a path like:
'your_project'/urls.py
path('/', include('home.urls')),
this added / always trigger this problem.
The only way i could solve was with a hacky fix. Simply give Django what it is seeking for :p
'your_project'/urls.py
def none_fix(request):
return render(request,'home/home.html')
urlpatterns = [
path('None', none_fix)]
I don't know if there is a clean way to fix it, and i don´t like the solution. This error might spot a broken code i didn´t find yet.
In my case the problem was contains with broken images with url('None').
You may try to find 'None' value in your Website, if you couldn't find it continue search in DevTools > Network page

Django Reason for getting TemplateSyntaxError?

I have created a new app called newsletters. I can access the pages when I write their location directly from local host by writing
http://127.0.0.1:8000/newsletters/signup/
but when I try to add their url in the nav bar I am getting an error:
TemplateSyntaxError at /
Invalid block tag on line 40: 'url'newsletters:subscribe''. Did you forget to register or load this tag?
Here are the main project urls:
urlpatterns = [
path('admin/', admin.site.urls),
path('newsletters/', include('newsletters.urls', namespace='newsletters')),
]
Here are newsletters app urls:
app_name = 'newsletters'
urlpatterns = [
path('signup/', newsletter_signup, name="subscribe"),
path('unsubscribe/', newsletter_unsubscribe, name='unsubscribe'),
]
here are the nav bar template:
<div class="dropdown-divider"></div>
<a class="dropdown-item" href=" {% url'newsletters:subscribe' %}">Newsletters</a>
<div class="dropdown-divider"></div>
How should I fix it and what am I have I done wrong to avoid it?
You're missing a space after url in your url tag:
{% url 'newsletters:subscribe' %}

How to include a link to reset password and register in Django views?

In my Django view, I use the following tags for logging in and logging out:
<href="{% url 'login' %}">
<href="{% url 'logout' %}">
What are the analogous tags for registering an account and resetting the password?
Currently I am doing this which feels rather ugly:
<href="/accounts/password/reset/">
<href="/accounts/register/">
What's the proper way to do this please?
Password Reset
As mentioned in the docs, it should be:
<a href="{% url 'password_reset' %}">
Registration
This is usually supported by third party libraries. It seems you might be using the django-registration default backend, in which case it is:
<a href="{% url 'registration_register' %}">
AFAIK you need to install django-registration to get these.
Then you can use:
{% url 'auth_password_reset' %}
{% url 'registration_register' %}
EDIT
For password reset you can use password_reset. See the docs.

Correct way to use Facebook Like plugin in Django

I am using the following Facebook code to show the Like plugin when iterating through my list of Post objects.
<fb:like href="{% url post post.id %}" layout="button_count" show_faces="false" width="450" font=""></fb:like>
The resulting HTML is as such:
<fb:like href="/9/" layout="button_count" show_faces="false" width="450" font=""></fb:like>
However, when I click the Like button, my FB profile says that I Liked www.facebook.com/9/ instead of my own domain name.
What did I do wrong?
Thank you!
The problem is that {% url post post.id %} returns an absolute url path without the domain. Facebook plugins need the full url with host. To make your page likable you also need to pass your domain somehow to the template. Lets assume you createa template variable host via request.get_host() in your views and pass it to your template then the url statement could look like this:
<fb:like href="http://{{host}}{% url post post.id %}" layout="button_count" show_faces="false" width="450" font=""></fb:like>