Greetings to Everyone

26 views
Skip to first unread message

Richard Dushime

unread,
Sep 15, 2021, 8:05:48 AMSep 15
to django...@googlegroups.com
i kindly need a help  i am making a static website into dynamic using Python Django and postgresql as my database
i created models then i went in admin to register them then views to create the function  after i went into html code to put the jijna format so that it can display at the end i made migrations and it accepted very well
1---- for home vieuw it accepting and display all the contents
2-- the problem comes to the second pages about us  that is where no content is being displayed but the content is all well in admin panel django site administration  i can add data but it can not display on about page
i am kindly asking for help  Down is all the files necessary
Here is my models
from django.db import models
from django.db.models.fields import CharField, DateField
from django.db.models.fields.files import ImageField

# Create your models here.
# slide show models
class home_slide(models.Model):
   
    s_title = models.CharField(max_length=100)
    s_description = models.TextField(max_length=150)
    s_button = models.CharField(max_length=20)
    s_image = ImageField(upload_to = 'media')

    class Meta():
        ordering = ("s_button","s_title","s_description")

    def __str__(self):
        return f"{self.s_title},{self.s_description},{self.s_button}"

# index -- course categories models

# short courses

class shortcourse(models.Model):
    sc_title = models.CharField(max_length=50)
    sc_description = models.TextField(max_length=300)
    sc_image = models.ImageField(upload_to = 'media')
    sc_button = models.CharField(max_length=20)

    def __str__(self):
        return f"{self.sc_title}, {self.sc_description},{self.sc_image},{self.sc_button}"


#testimonials

class testimonial(models.Model):
    t_name = models.CharField(max_length=50)
    t_categorie = models.CharField(max_length=20)
    t_quote = models.TextField(max_length=300)
    t_image = models.ImageField(upload_to='media/testimonials')

    def __str__(self):
        return f"{self.t_name}, {self.t_categorie},{self.t_quote},{self.t_image}"

#publications and news

class publication(models.Model):
    p_date = models.DateField()
    p_title = models.CharField(max_length=200)
    p_description = models.TextField(max_length=400)
    p_button = models.CharField(max_length=15)

    def __str__(self):
        return f"{self.p_date}, {self.p_title}, {self.p_description}, {self.p_button}"


#  campus life style

class campuslife(models.Model):
    cl_title = models.CharField(max_length=50)
    cl_date = models.DateTimeField()
    cl_description = models.TextField()
    cl_image = models.ImageField(upload_to='media/campuslife')

    def __str__(self):
        return f"{self.cl_title}, {self.cl_date},{self.cl_description},{self.cl_image}"

# Gallery

class gallery(models.Model):
    g_image = models.ImageField(upload_to ='media/Gallery')

    def __str__(self):
        return f"{self.g_image}"


"""
About us

"""
# home

class About(models.Model):
    a_title = models.CharField(max_length=150)
    a_desc = models.TextField(max_length=200)
    a_image = models.ImageField(upload_to ='media/About')

    def __str__(self):
        return f"{self.a_title},{self.a_desc},{self.a_image}"

class description(models.Model):
    d_title = models.CharField(max_length=200)
    d_desc = models.TextField(max_length=1000)

    def __str__(self):
        return f"{self.d_title},{self.d_desc}"


"""
Admin
"""
from django.contrib import admin
from schoolofci.models import About, campuslife, description, gallery, home_slide, publication, shortcourse, testimonial

# Register your models here.
# home admin section
@admin.register(home_slide)
class HomeSlideAdmin(admin.ModelAdmin):
    list_display = ("s_title","s_description","s_button","s_image")
    list_filter = ("s_button",)
    fields = ("s_title","s_description","s_button","s_image")

# courses  categories

# short courses
@admin.register(shortcourse)
class ShortCourse(admin.ModelAdmin):
    list_display = ("sc_title","sc_description","sc_button","sc_image")
    list_filter = ("sc_title",)
    fields = ("sc_title","sc_description","sc_image","sc_button")

# testimonials
@admin.register(testimonial)
class Testimonial(admin.ModelAdmin):
    list_display = ("t_name","t_categorie","t_quote","t_image")
    list_filter = ("t_name",)
    fields = ("t_name","t_categorie","t_quote","t_image")


# publications
@admin.register(publication)
class Publications(admin.ModelAdmin):
    list_display = ("p_date","p_title","p_description","p_button")
    list_filter = ("p_title",)
    fields = ("p_date","p_title","p_description","p_button")

# campus life
@admin.register(campuslife)
class Campuslife(admin.ModelAdmin):
    list_display = ("cl_title","cl_date","cl_description","cl_image")
    list_filter = ("cl_title",)
    fields = ("cl_title","cl_date","cl_description","cl_image")


# gallery

@admin.register(gallery)
class Gallery(admin.ModelAdmin):
    list_display = ("g_image",)




"""
About us page

"""
# home slides
@admin.register(About)
class Aboutus(admin.ModelAdmin):
    list_display = ("a_title", "a_desc", "a_image")
    list_filter = ("a_title",)
    fields = ("a_title","a_desc","a_image")

# description
@admin.register(description)
class Description(admin.ModelAdmin):
    list_display = ("d_title","d_desc")
    list_filter = ("d_title",)
    fields = ("d_title","d_desc")


"""
Views
"""
from schoolofci.admin import Description, Gallery
from schoolofci.models import About, campuslife, description, gallery,home_slide, publication, shortcourse, testimonial
from django.shortcuts import render

# Create your views here.
def index(request):
    slides = home_slide.objects.all()
    shortcourses = shortcourse.objects.all()
    testimonialss = testimonial.objects.all()
    publications = publication.objects.all()
    camplife = campuslife.objects.all()
    Galery = gallery.objects.all()

    home = {"slides":slides,"shortcourses":shortcourses, "publications":publications,
            "testimonialss":testimonialss, "camplife":camplife , "Galery":Galery}

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

# about section
def about(request):
    About_slides = About.objects.all()
    Description = description.objects.all()

    abt = {"About_slides":About_slides,"Description":Description}

    return render(request, 'about.html')

"""
Html code

about us page
"""

{% for abtslide in About_slides %}
<aside id="fh5co-hero">
<div class="flexslider">
<ul class="slides">
<li style="background-image: url({{abtslide.a_image.url}});">
  <div class="overlay-gradient"></div>
  <div class="container">
  <div class="row">
  <div class="col-md-8 col-md-offset-2 text-center slider-text">
  <div class="slider-text-inner">
  <h1 class="heading-section">{{abtslide.a_title}}</h1>
<h2>{{abtslide.a_desc}}</h2>
  </div>
  </div>
  </div>
  </div>
  </li>
  </ul>
  </div>
</aside>
{% endfor %}

{% for abt in Description %}
<div id="fh5co-about">
<div class="container">
<h2>{{abt.d_title}}</h2>
<p>{{abt.d_desc}}</p>

<button type="button" class="btn btn-outline-success">Join Us</button>
</div>
</div>
{% endfor %}

<div id="fh5co-gallery" class="fh5co-bg-section">
<div class="row text-center">
<h2><span>Gallery</span></h2>
</div>
<div class="row">
{% for image in Galery %}
<div class="col-md-3 col-padded">
<a href="#" class="gallery" style="background-image: url({{image.g_image.url}});"></a>
</div>
{% endfor %}
</div>

</div>

"""
Home

"""

<aside id="fh5co-hero">
<div class="flexslider">
<ul class="slides">
{% for slide in slides %}
  <li style="background-image: url({{slide.s_image.url}});">
  <div class="overlay-gradient"></div>
  <div class="container">
  <div class="row">
  <div class="col-md-8 col-md-offset-2 text-center slider-text">
  <div class="slider-text-inner">
  <h1>{{slide.s_title}}</h1>

<h2> {{slide.s_description}} <a href="" target="_blank">more</a></h2>
<p><a class="btn btn-primary btn-lg" href="#">{{slide.s_button}}</a></p>
  </div>
  </div>
  </div>
  </div>
  </li>
{% endfor %}
  </ul>
  </div>
</aside>
<section id = "academies">
<div id="fh5co-course">
<div class="container">
<center><h2>School of Computing and Informatics (SCI)</h2></center>
<p>Thing.</p>

<div class="row">
{% for sc in shortcourses %}
<div class="col-md-6 animate-box">
<div class="course">
<a href="#" class="course-img" style="background-image: url({{sc.sc_image.url}});">
</a>
<div class="desc">
<h3><a href="#">{{sc.sc_title}}</a></h3>
<p>{{sc.sc_description}}</p>
<span><a href="#" class="btn btn-primary btn-sm btn-course">{{sc.sc_button}}</a></span>
</div>
</div>
</div>
{% endfor %}
</div>



<div id="fh5co-testimonial" style="background-image: url(images/school.jpg);">
<div class="overlay"></div>
<div class="container">
<div class="row animate-box">
<div class="col-md-6 col-md-offset-3 text-center fh5co-heading">
<h2><span>Testimonials</span></h2>
</div>
</div>

<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="row animate-box">
<div class="owl-carousel owl-carousel-fullwidth">
{% for test in testimonialss %}
<div class="item">
<div class="testimony-slide active text-center">
<div class="user" style="background-image: url({{test.t_image.url}});"></div>
<span>{{test.t_name}}<br><small>{{test.t_categorie}}</small></span>
<blockquote>
<p>{{test.t_quote}}</p>
</blockquote>
</div>
</div>

{% endfor %}
</div>
</div>
</div>
</div>

</div>
</div>

<div id="fh5co-blog">

<div class="container">
<section id = "publication">
<div class="row animate-box">
<div class="col-md-8 col-md-offset-2 text-center fh5co-heading">
<h2>Publications, News &amp; Events</h2>
<p>Explore recent news about our research, events, and accomplishments. </p>
</div>
</div>
<div class="row row-padded-mb">
{% for pub in publications %}
<div class="col-md-4 animate-box">
<div class="fh5co-event">
<div class="date text-center"><span>{{pub.p_date}}</span></div>
<h3><a href="#">{{pub.p_title}}</a></h3>
<p>{{pub.p_description}}</p>
<p><a  href="{% url 'blog' %}">Read More</a></p>
</div>
</div>
  {% endfor %}

</div>
</section>

<section id = "campuslife">
<div class="row animate-box">
<div class="col-md-8 col-md-offset-2 text-center fh5co-heading">
<h2> Campus Life </h2>
<p>Explore recent news about our research, events, and accomplishments. </p>
</div>
</div>
<div class="row">
{% for clife in camplife %}
<div class="col-lg-4 col-md-4">

<div class="fh5co-blog animate-box">
<a href="#" class="blog-img-holder" style="background-image: url({{clife.cl_image.url}});"></a>
<div class="blog-text">
<h3><a href="#">{{clife.cl_title}}</a></h3>
<span class="posted_on">{{clife.cl_date}}</span>
<span class="comment"><a href="">21<i class="icon-speech-bubble"></i></a></span>
<p>{{clife.cl_description}}</p>
</div>
</div>
{% endfor %}
</section>

</div>
</section>
</div>
</div>

<div id="fh5co-gallery" class="fh5co-bg-section">
<div class="row text-center">
<h2><span>Gallery</span></h2>
</div>
<div class="row">
{% for image in Galery %}
<div class="col-md-3 col-padded">
<a href="#" class="gallery" style="background-image: url({{image.g_image.url}});"></a>
</div>
{% endfor %}
</div>
</div>

Ahmet Faruk Yılmaz

unread,
Sep 15, 2021, 9:22:10 AMSep 15
to Django users
Hello, 
Could you please upload your code to GitHub or some other platform ? It is really hard to read and track the code.

15 Eylül 2021 Çarşamba tarihinde saat 15:05:48 UTC+3 itibarıyla mudahe...@gmail.com şunları yazdı:

Sebastian Jung

unread,
Sep 15, 2021, 9:57:09 AMSep 15
to django...@googlegroups.com
Hello,

answer ist relativ simple: 

Code:

  abt = {"About_slides":About_slides,"Description":Description}

    return render(request, 'about.html')

you don't insert context in render. Right line:

return render(request, 'about.html',abt)

Regards


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJCm56Kn2%2BAAv9q1PnpG1gq6uu%3DaJyQ5mQ32hX1M9QGajY_s8g%40mail.gmail.com.

MR INDIA

unread,
Sep 15, 2021, 9:58:50 AMSep 15
to Django users
Jinja 2 is quite different from django templates and you need to use . Jinja file extension. And configure it. And pls send GitHub link, and is there any error log or Trace back then send it. 

Richard Dushime

unread,
Sep 18, 2021, 1:42:24 PMSep 18
to django...@googlegroups.com
Thanks for the help it worked 

--
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.
Reply all
Reply to author
Forward
0 new messages