在Django上制作印章/徽章/小工具可以通过以下步骤实现:
django-admin startproject project_name
python manage.py startapp app_name
from django.db import models
class Badge(models.Model):
name = models.CharField(max_length=100)
image = models.ImageField(upload_to='badges/')
description = models.TextField()
def __str__(self):
return self.name
python manage.py makemigrations
python manage.py migrate
from django.shortcuts import render
from .models import Badge
def badge_list(request):
badges = Badge.objects.all()
return render(request, 'badge_list.html', {'badges': badges})
{% for badge in badges %}
<div>
<h3>{{ badge.name }}</h3>
<img src="{{ badge.image.url }}" alt="{{ badge.name }}">
<p>{{ badge.description }}</p>
</div>
{% endfor %}
from django.urls import path
from app_name.views import badge_list
urlpatterns = [
path('badges/', badge_list, name='badge_list'),
]
python manage.py runserver
现在,你可以通过访问http://localhost:8000/badges/来查看所有徽章的列表。
推荐的腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云