Certainly! Below is a simple base.html template for a Django dashboard project using Tailwind CSS. This template is mobile-friendly and includes a navigation bar. I've used placeholders for Django template tags instead of the actual syntax.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}Dashboard{% endblock %}</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100">
<!-- Sidebar -->
<div class="flex h-screen">
<div class="flex flex-col w-64 bg-white border-r">
<div class="flex items-center justify-center h-16 border-b">
<h1 class="text-xl font-bold">Dashboard</h1>
</div>
<nav class="flex-1 p-4">
<ul>
<li class="mb-2">
<a href="{% url 'home' %}" class="block p-2 text-gray-700 rounded hover:bg-gray-200">Home</a>
</li>
<li class="mb-2">
<a href="{% url 'profile' %}" class="block p-2 text-gray-700 rounded hover:bg-gray-200">Profile</a>
</li>
<li class="mb-2">
<a href="{% url 'settings' %}" class="block p-2 text-gray-700 rounded hover:bg-gray-200">Settings</a>
</li>
<li class="mb-2">
<a href="{% url 'logout' %}" class="block p-2 text-gray-700 rounded hover:bg-gray-200">Logout</a>
</li>
</ul>
</nav>
</div>
<!-- Main content -->
<div class="flex-1 p-6">
<header class="flex items-center justify-between mb-4">
<h2 class="text-2xl font-semibold">{% block header %}Dashboard Header{% endblock %}</h2>
<div>
<button class="p-2 text-white bg-blue-500 rounded hover:bg-blue-600">Add New</button>
</div>
</header>
<main>
{% block content %}
<p>Welcome to your dashboard!</p>
{% endblock %}
</main>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/alpinejs@2.8.2/dist/cdn.min.js" defer></script>
</body>
</html>
Explanation:
- Responsive Design: The layout is built using Flexbox, which makes it responsive and mobile-friendly.
- Sidebar Navigation: The sidebar contains links to different sections of the dashboard. You can replace the
{% url '...' %} placeholders with your actual URL names.
- Main Content Area: The main content area is where the specific content for each page will be rendered. You can define different headers and content for each page by overriding the
{% block header %} and {% block content %} sections.
- Tailwind CSS: The template uses Tailwind CSS for styling. You can customize the styles as needed.
Usage:
To use this template, save it as base.html in your Django templates directory. Then, create other templates that extend this base template and fill in the blocks as needed. For example:
{% extends 'base.html' %}
{% block title %}Home{% endblock %}
{% block header %}Welcome to the Dashboard{% endblock %}
{% block content %}
<p>This is the home page content.</p>
{% endblock %}
This structure allows you to maintain a consistent layout across your dashboard while easily customizing individual pages.