keshav khanal
keshav khanal

Reputation: 51

How can i solve this issue error during template rendering rendering django?

Error during template rendering in django I'm trying to run the server but it always shows this error. How can i solve this issue.

In my item_list.html

{% extends "main/base.html" %}

{% block body %}
    <h1>Here is the list of items.</h1>
    
    {% for item in items %}
        {{ item }}
    {% endfor %}

{% endblock %}

In base.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>merobooks</title>
</head>
<body>
    
    {% block body %}
    
    {% endblock %}
    
</body>
</html>

in views.py

from django.shortcuts import render
from . models import Item

def item_list(request):
    context = {
        'items': Item.objects.all()
    }
    return render(request, 'main/item_list.html', context)

In urls.py

from django.urls import path
from . import views

app_name = 'main'

urlpatterns = [
    path('', views.item_list, name='item-list')
]

This shows the following error

ProgrammingError at /
relation "main_item" does not exist
LINE 1: ...d", "main_item"."title", "main_item"."price" FROM "main_item...
                                                             ^
Request Method: GET
Request URL:    http://localhost:8000/
Django Version: 3.0.8
Exception Type: ProgrammingError
Exception Value:    
relation "main_item" does not exist
LINE 1: ...d", "main_item"."title", "main_item"."price" FROM "main_item...
                                                             ^
Exception Location: C:\Users\keskh\.virtualenvs\merobooks-K3uFXFWX\lib\site-packages\django\db\backends\utils.py in _execute, line 86
Python Executable:  C:\Users\keskh\.virtualenvs\merobooks-K3uFXFWX\Scripts\python.exe
Python Version: 3.8.1
Python Path:    
['C:\\Users\\keskh\\Desktop\\Python\\dev\\djangoDev\\merobooks',
 'C:\\Users\\keskh\\.virtualenvs\\merobooks-K3uFXFWX\\Scripts\\python38.zip',
 'c:\\users\\keskh\\appdata\\local\\programs\\python\\python38-32\\DLLs',
 'c:\\users\\keskh\\appdata\\local\\programs\\python\\python38-32\\lib',
 'c:\\users\\keskh\\appdata\\local\\programs\\python\\python38-32',
 'C:\\Users\\keskh\\.virtualenvs\\merobooks-K3uFXFWX',
 'C:\\Users\\keskh\\.virtualenvs\\merobooks-K3uFXFWX\\lib\\site-packages']
Server time:    Fri, 31 Jul 2020 01:37:34 +0000

relation "main_item" does not exist LINE 1: ...d", "main_item"."title", "main_item"."price" FROM "main_item... ^

I'm trying to run the server but it doesn't work. Always shows above error. How can i solve this issue. help needed

Upvotes: 0

Views: 1189

Answers (2)

patbet
patbet

Reputation: 93

Had the same issue and spent a lot of time checking the files for typos and other issues, to perform the migrations is pretty obvious still easily forgotten.

manage.py makemigrations
manage.py migrate 
manage.py runserver

fixed the issue for me, well done!

Upvotes: 1

Rocky
Rocky

Reputation: 38

I would leave this as a comment but my reputation apparently is too low.

From the error it looks like the main_item table does not exist in your database. Maybe you haven't performed your migrations?

Try running this:

./manage.py makemigrations
./manage.py migrate

Upvotes: 1

Related Questions