Facing problem to display dynamic (name,description of places AND price)on the web page using Django

39 views
Skip to first unread message

UJJWAL AGRAWAL

unread,
Jun 3, 2021, 9:17:25 AM6/3/21
to django...@googlegroups.com
Dear team

I am facing a problem with error

While writing this code

ERROR IS: RETURN OUTSIDE FUNCTION

Please help  me solving this issue.

from django.shortcuts import render
from .models import Destination
# Create your views here.
def index(request):
    dest1 = Destination()
    dest1.name ='Jaipur'
    dest1.desc ='The pink city Gulaabi nagar'
    dest1.price = 900

def index(request):
    dest2 = Destination()
    dest2.name ='Udaipur'
    dest2.desc ='The  city of lakes'
    dest2.price = 1200

def index(request):
    dest3 = Destination()
    dest3.name ='Bharatpur'
    dest3.desc ='The city of warriors'
    dest3.price = 1100


dests =[dest1, dest2 , dest3]
return render(request,"index.html",{'dests':dests})



Nandaniya Nilesh

unread,
Jun 3, 2021, 9:37:24 AM6/3/21
to django...@googlegroups.com
hello,
I am nilesh,
i think every funtion should return something.

return dests from index named function.
last line is not with any function


def main():
           
          ......
         def  index():
                  ......
                  return dest1
         def  index():
                  ......
                   return dest2
         def  index():
                  ......
                   return dest3

          dests  =  [...]
           return   render(.......)       
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Sent from Mailspring

Michael Smith

unread,
Jun 3, 2021, 9:52:57 AM6/3/21
to django...@googlegroups.com
You can't have three of the same name view either can you?

Bradie Poa

unread,
Jun 6, 2021, 4:22:31 PM6/6/21
to django...@googlegroups.com
please use the code below:

def index(request):
context = {}

        return render(request, 'index.html' , context)

Reply all
Reply to author
Forward
0 new messages