Need help, Very new to Django.
I have created a model as below
class Redirect_url(models.Model):
hosturl = models.CharField(max_length=100)
path = models.CharField(max_length=100)
redirectpage = models.CharField(max_length=200)
I need the hosturl, path and redirectpage as a variable in my views page for me to make some logic before I render to the html page. I don’t know
from django.shortcuts import render,redirect
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from .import models
def home(request):
return render(request,'home.html')
def redurl(request):
b = request
data = (models.Redirect_url.objects.all())
print(data)
return HttpResponse(data, content_type="text/plain")
I am getting print as Redirect_url object (1)Redirect_url object (2). How to get all the models data. Thanks.
models.Redirect_url.objects.all()(which is aQuerySetobject) as the response. Python is simply trying to create a readable representation of this object, which in this case is "Redirect_url object (1)Redirect_url object (2)" (a list of the two objects in the QuerySet). You should instead either create and render a template that displays what you want the user to see, or you should create a more readable string