나는 장고 웹 개발의 준결승이다. 나는 실제로 포스트에 이미지를 업로드 할 수있는 파일 필드를 추가했습니다 (이미지는 포스트 목록과 포스트 세부 사항으로 표시됩니다). 그러나 게시물에 여러 이미지를 추가하고 싶다면 어떻게해야합니까?블로그 게시물에 여러 개의 이미지를 삽입하는 방법 파일 필드 업로드 (Django 블로그)
현재 튜토리얼 게시물을 작성 중이며 사용자를 위해 각 지침에 이미지를 삽입하고 싶습니다. 튜토리얼을 순수 텍스트로 만들고 싶지는 않습니다. 어떻게해야합니까? 다음은
내 models.pyfrom __future__ import unicode_literals
from django.db import models
from django.core.urlresolvers import reverse
from django.utils import timezone
#from taggit.managers import TaggableManager
class Post(models.Model):
author = models.ForeignKey('auth.User')
title = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(default=timezone.now)
published_date = models.DateTimeField(blank=True, null=True)
image = models.FileField(null=True, blank=True)
#tags = TaggableManager()
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.title
def approved_comments(self):
return self.comments.filter(approved_comment=True)
class Meta:
ordering = ["-pk"]
class Comment(models.Model):
post = models.ForeignKey('blog.Post', related_name='comments')
author = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(default=timezone.now)
approved_comment = models.BooleanField(default=False)
def approve(self):
self.approved_comment = True
self.save()
def approved_comments(self):
return self.comments.filter(approved_comment=True)
def __str__(self):
return self.text
입니다 그리고 여기 당신이 그냥 링크 때를 게시하고 볼 수 있듯이, 여기 내 forms.py
from django import forms
from .models import Post, Comment
class PostForm(forms.ModelForm):
class Meta:
model = Post
fields = ('image','title', 'text')
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ('author', 'text',)
의 내 블로그 게시물의 스크린 샷입니다
마지막으로 아래그리고는 SNI 인 HTML 파일을 포함 게시물 세부 사항의 ppet;
는{% extends 'blog/base.html' %}
{% block content %}
\t \t {% if user.is_authenticated %}
\t \t <a class="btn btn-default pull-left" href="{% url 'post_edit' pk=post.pk %}"><span class="glyphicon glyphicon-pencil"></span></a>
\t \t {% endif %}
\t \t <div id="post_det">
\t \t \t {% if post.published_date %}
\t \t \t \t <div class="date">
\t \t \t \t \t {{ post.published_date }}
\t \t \t \t </div>
\t \t \t {% endif %}
\t \t \t <h1 class="post-title">{{ post.title }}</h1>
\t \t \t \t <img src="{{post.image.url}}" class="img-responsive blog-img"/>
\t \t \t \t
\t \t \t \t
\t \t \t <p class="post_text">{{ post.text|linebreaksbr }}</p>
\t \t \t
\t \t \t
\t \t </div>
\t
\t
\t <hr>
\t \t <a class="btn comment_button" href="{% url 'add_comment_to_post' pk=post.pk %}">Add comment</a>
\t \t
\t
\t <div>
\t
\t
\t \t {% for comment in post.comments.all %}
\t \t {% if user.is_authenticated or comment.approved_comment %}
\t \t \t <div class="comment">
\t \t \t <div class="date">
{{ comment.created_date }}
{% if not comment.approved_comment %}
<a class="btn btn-default" href="{% url 'comment_remove' pk=comment.pk %}"><span class="glyphicon glyphicon-remove"></span></a>
<a class="btn btn-default" href="{% url 'comment_approve' pk=comment.pk %}"><span class="glyphicon glyphicon-ok"></span></a>
{% endif %}
\t \t \t </div>
\t \t \t <strong>{{ comment.author }}</strong>
\t \t \t <p>{{ comment.text|linebreaks }}</p>
\t \t \t </div>
\t \t {% endif %}
\t \t \t {% empty %}
\t \t \t \t <p>No comments here yet :(</p>
\t \t \t {% endfor %}
\t </div>
{% endblock %}
이 같은 천한 작업처럼 보인다 나는 일부 텍스트 아래에 간단한 이미지를 삽입하기 위해 고군분투하고있다. 아무도 도와 줄 수 있니? 그것을 크게 감사 할 것입니다.
는샘
그렇다면 여러 개의 이미지를 추가 하시겠습니까? 또는 이미지가 올바르게 렌더링되지 않았습니까? –
@ alfonso.kim 블로그 게시물에 여러 개의 이미지를 삽입하고 싶습니다. 지금은 게시물을 올리는 방법 만 알면 내 게시물 세부 정보 스 니펫에서 볼 수 있듯이 models.py 파일을 편집해야합니까? 감사합니다 – Curly77