Test Blog

Published on January 29, 2026 by mohitsaluja@gmail.com
2 min read
0 Likes

Login to like

0 Comments

Share this post:

from django.shortcuts import render
from django.contrib import messages
from .models import Profile, HomeSection
from blog.models import Blog

def home(request):
    # Fetch hero section data
    hero_data = {
        'title': 'Welcome to TechBlog',
        'subtitle': 'Your go-to source for insights on tech, DevOps, Kubernetes, and automation. Discover the latest trends, tutorials, and best practices in the tech world.'
    }
    
    hero_title = HomeSection.objects.filter(section_type='hero_title', is_active=True).first()
    hero_subtitle = HomeSection.objects.filter(section_type='hero_subtitle', is_active=True).first()
    
    if hero_title:
        hero_data['title'] = hero_title.content
    if hero_subtitle:
        hero_data['subtitle'] = hero_subtitle.content
    
    # Fetch feature cards
    features = HomeSection.objects.filter(section_type='feature', is_active=True).order_by('order')
    
    # Fetch CTA section data
    cta_data = {
        'title': 'Ready to Dive In?',
        'text': 'Join our community of tech enthusiasts. Stay updated with the latest posts and share your thoughts.'
    }
    
    cta_title = HomeSection.objects.filter(section_type='cta_title', is_active=True).first()
    cta_text = HomeSection.objects.filter(section_type='cta_text', is_active=True).first()
    
    if cta_title:
        cta_data['title'] = cta_title.content
    if cta_text:
        cta_data['text'] = cta_text.content
    
    # Fetch recent blogs for optional display
    recent_blogs = Blog.objects.filter(status='published').order_by('-created_at')[:3]
    
    context = {
        'hero_data': hero_data,
        'features': features,
        'cta_data': cta_data,
        'recent_blogs': recent_blogs,
    }
    
    return render(request, "home.html", context)

def profile(request):
    profile = Profile.objects.first()
    if profile:
        profile.skills_list = [skill.strip() for skill in profile.skills.split(',') if skill.strip()] if profile.skills else []
    return render(request, "profile.html", {"profile": profile})

def contact(request):
    profile = Profile.objects.first()
    
    if request.method == 'POST':
        name = request.POST.get('name')
        email = request.POST.get('email')
        subject = request.POST.get('subject')
        message_text = request.POST.get('message')
        
        if name and email and subject and message_text:
            # Here you can add email sending logic
            # For now, we'll just show a success message
            messages.success(request, 'Thank you for your message! We will get back to you soon.')
            return render(request, 'contact.html', {'profile': profile})
        else:
            messages.error(request, 'Please fill in all fields.')
    
    return render(request, 'contact.html', {'profile': profile})

Comments (0)

Login to comment on this post.

No comments yet. Be the first to comment!

Related Posts

Monitoring and Observability: The DevOps Perspective

Master monitoring, logging, and observability practices to maintain healthy production systems.

2 min
0
Read more

Infrastructure as Code with Terraform

Manage your cloud infrastructure using code with Terraform for reproducibility and version control.

2 min
0
Read more

Jenkins Pipeline: Automating Your Build Process

Learn how to build powerful CI/CD pipelines using Jenkins declarative and scripted pipelines.

2 min
0
Read more

Docker and Kubernetes: Container Orchestration Essentials

Master containerization and orchestration with Docker and Kubernetes for scalable applications.

2 min
0
Read more