Django Error Not Found: /NONE in server log - django-views

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

Related

Django - button redirecting to {% url 'index' %}

I can't find any solution on any article so I'm asking here.
I'd like to make button which is gonna redirect user to specific url.
I have already did it this way:
<button onclick="location.href='create_recipe/'" type="button" >Create new Recipe</button>
but instead of passing whole link I'd like to use {% url 'some_view' %} but I do not have an idea how I should do that.
Is it even possible to do that ?
It has to be <button>,
edit:
something like:
<button type="button" class="btn btn-outline-secondary">Create new Recipe</button>
also does not work
You can do this by adding this to the button:
onclick="goToSomeView()"
And then add this in script tag of html file:
<script type="text/javascript">
function goToSomeView(){
document.location.href = "{% url 'some_view' %}"
}
</script>
index is your function which exist views.py file.
from django.urls import path
from . import views
path('',views.index, name='index'),
HTML:
<a class="btn btn-outline-secondary" href="{% url 'index' %}">Create new Recipe</a>
As I see you're using bootstrap already, so the easiest way is to use the a element with the type="button" attribute.
Create new recipe
Below you can see that the result is the same, but for button you need to bind the onclick function. In this case I pointed to #nigel239 answer.
function goToSomeView(){
document.location.href = "{% url 'index' %}"
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<p class="lead">Using 'a' element</p>
Create new recipe
<p class="lead mt-3">Using button</p>
<button onclick="goToSomeView()" class="btn btn-outline-secondary">Create new recipe</button>

Reverse for '' not found Django

Can't find the problem
urls.py
path("office", views.office, name="office")
views.py
def office(request):
offices_list = Office.objects.all()
context = {'offices_list': offices_list}
return render(request, "auctions/office.html", context)
template
<li class="nav-item">
<a class="nav-link text-white " href="{% url 'office' %}">office</a>
</li>
Error:
Reverse for '' not found. '' is not a valid view function or pattern name.
had to delete html page and rebuild it.
worked like charm.
still do not know what the issue was .
Thank you all for your kind contribution !

NoReverseMatch with slug variable, works with hard coded value

I'm updating some code from a Django 1.11 project to Django 2.x, and in one template (contacts list view with FK back to Clients), I am getting "NoReverseMatch" since it is not seeing the slug value in the URL parameter. If I hard code the value it works, and the same variable displays the proper value for each record if I just display as text on the page.
I don't see why the variable is getting dropped, but probably something stupid I've done.
This works:
<td class="">
<a href="{% url "clients:view" slug='sony' %}">
{{ contact.client.slug }}
</a>
</td>
This gets the NoReverse Error
<td class="">
<a href="{% url "clients:view" slug=contact.client.slug %}">
{{ contact.client.slug }}
</a>
</td>
In both cases, the variable {{ contact.client.slug }} returns the proper data.
urls.py:
import ...
app_name = "clients"
urlpatterns = [
path("ajax/validate_client_code", validate_client_code, name="validate_client_code"),
path("", ClientListView.as_view(), name="list"),
path("new/", ClientCreateView.as_view(), name="new"),
path("edit/<slug:slug>/", ClientUpdateView.as_view(), name="edit"),
path("delete/<int:pk>/", ClientDeleteView.as_view(), name="delete"),
path("<slug:slug>/", ClientDetailView.as_view(), name="view"),
]
Can anyone point out my mistake? Has to be something really simple, but I just cant see it.

Getting an 'x' in the url derived from django regex

I am trying to generate an URL using regex and have got it to an extent. But, the problem is there is an 'x' in the URL which I don't want there, without it the URL is perfect. I have tried few changes on the regex but removing or adding anything throws an error.
views.py
def clothes_details(request,slug):
item = data.objects.get(slug=slug)
print(item)
return render(request,clothes_details.html,{'item':item})
urls.py
url(r'^(?P<designerlink>)[\w-]+/(?P<slug>[\w-]+)/$',views.clothes_details,name='clothes_details'),
item.html
<div class='items'>
{% for item in all_clothes %}
<div class='item'>
<a href="{% url 'clothes_details' designerlink=item.designerlink slug=item.slug %}">
<img src="{{item.itemimage.url}}" style="width:350px;height:450px;">
</a>
<p>{{item.itemcode}}</p>
<p>{{item.itemprice}}</p>
<p>{{item.itemname}}</p>
</div>
The result is getting 'http://127.0.0.1:8000/designernamex/dressname/' but I need to get 'http://127.0.0.1:8000/designername/dressname/'

Django navigation issue

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