Reputation: 63
I am new to Django and Python. This is my first post here!:
I have been trying to "print" on some website I made with Django some objects from a database that I made with HeidySQL.
The app inside Django is called users. So 127.0.0.1: 8000/users, inside this I have another page in 127.0.0.1:8000/users/login that is loading fine.
I successfully synced this DB with Django, I even managed to see some rows in the Django shell, which is why I concluded everything seems to be connected well.
This login.html file atm has this:
{% block content %}
<h1>{{ allcharacters_query }} </h1>
</body>
{% endblock %}
The issue is that it doesn't display the names of my characters_list.
Here is my views.py:
from django.http import HttpResponse
from django.shortcuts import render
from users.models import Characters
from django.template.response import TemplateResponse
def index (request):
return render(request,'users/home.html')
def return_charnames (request):
allcharacters_query = Characters.objects.all()
return render(request, 'users/login.html',{"allcharacters_query":
allcharacters_query})
And this my urls.py file:
from django.conf.urls import url, include, patterns
from .import views
from django.contrib.auth.views import login
urlpatterns = [
url(r'^$', views.index,name='index'),
url(r'^login/$',login,{'template_name': 'users/login.html' })
]
I don't really know how to fix this. I have read lots of documentation from the official Django site and watched lots of videos, however, I am stuck here. Thanks all!
Upvotes: 0
Views: 320
Reputation: 2116
You've to use your view render not django's views for login if you're overriding login methods.
url(r'^login/$',views.return_charnames)
Upvotes: 1
Reputation: 1984
Replace
{% for lista in characters_list %}
by:
{% for lista in allcharacters_query %}
characters_list
doesn't exist in your template.
And there is no URL calling your view return_charnames
in your url file.
Upvotes: 0
Reputation: 705
You should add return_charnames to urls.py to display html content in proper url.
Upvotes: 0