Python Forum
how retrieve database save multiple data in web Django 2.1
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how retrieve database save multiple data in web Django 2.1
#1
i'm making a web site for post data from database.in my database have many data fields. i can retrieve one data from database.but when trying to get multiple data to retrieve in web page i got errors.
i using django 2.1

Help me to how get multiple data from database and retrieve in webpage

views.py
from django.shortcuts import render
from .models import data

# Create your views here.
def index(request):
    return render(request, 'index.html')

def about(request):
    return render(request, 'about.html')

def postjob(request):

        obj = data.objects.all()
        for i in obj:
            print("i :", i)
            context = {
                "title": i.title,
                "jobType": i.jobType,
                "des": i.description,
                "jImg": i.jImg
            }
            print("context:", context)
        return render('jobpost.html', context)

models.py
from django.db import models

# Create your models here.
class data(models.Model):
    title = models.TextField()
    jobType = models.TextField()
    description = models.TextField()
    jImg = models.ImageField(upload_to="media")
urls.py
"""webDiligent URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from diligent.views import index, about, postjob
from webDiligent import settings
from django.contrib.staticfiles.urls import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns


urlpatterns = [
    path('admin/', admin.site.urls),
    path('', index, name='index'),
    path('about/', about, name='about'),
    path('jobpost/', postjob, name='postjob'),
]



urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
jobpost.html

<div class="row">
					{% for con in context %}
					<!-- single product -->
					<div class="col-lg-4 col-md-6">
						<div class="single-product">

							<img class="img-fluid" src="{{jImg.url}}" alt="">

							<div class="product-details">
								<h5>{{title}}</h5>
								<div class="price">
									<h6>{{jobType}}</h6>
									<p>{{description}}</p>
								</div>
								<div class="prd-bottom"><a href="submitcv.html">Send Your CV</a></div>
							</div>
						</div>
					</div>
					{% endfor %}
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Django: View is unable to find attributes of database model pythonpaul32 0 484 Dec-07-2023, 06:38 PM
Last Post: pythonpaul32
  Retrieve data from ajax pthon3 0 1,162 May-29-2022, 10:32 PM
Last Post: pthon3
  Save JSON data to sqlite database on Django Quin 0 2,804 Mar-26-2022, 06:22 PM
Last Post: Quin
  trying to save data automatically from this page thunderspeed 1 1,975 Sep-19-2021, 04:57 AM
Last Post: ndc85430
  DJANGO Looping Through Context Variable with specific data Taz 0 1,782 Feb-18-2021, 03:52 PM
Last Post: Taz
Question wkhtmltoimage generated jpeg save to Database using mongoengine Madoo 2 3,030 Aug-18-2020, 03:42 PM
Last Post: Madoo
  How to make data coming from a database clickable giving more details newbie1 8 3,673 May-29-2020, 11:19 PM
Last Post: newbie1
  Send email to gmail after user fill up contact form and getting django database updat Man_from_India 0 2,071 Jan-22-2020, 03:59 PM
Last Post: Man_from_India
  how to save the data from MySQL to CSV in Flask farah97 4 2,899 Jan-03-2020, 03:02 AM
Last Post: farah97
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,247 Jun-30-2019, 12:21 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020