-2
我有這個在我的數據庫Django的博客與圖片
1款
1款
1款
我想放置的圖片在段落之間。
我想這
<img src="where/photo/is">
class Post(models.Model):
STATUS_CHOICES = (
('draft','Draft'),
('published', 'Published'),
)
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250, unique_for_date ='publish')
author = models.ForeignKey(User, related_name='blog_posts')
body = models.TextField()
publish = models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
image = models.ImageField(upload_to='posts', default='path/to/my/default/image.jpg')
status = models.CharField(max_length=10, choices=STATUS_CHOICES,
default='draft')
objects = models.Manager()
published = PublishedManager()
tags = TaggableManager()
class Meta:
ordering = ('-publish',)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('blog:post_detail',
args=[self.slug])
注意:這是後表發生在段落中的數據,也沒有想象之間,我想它得到這個文本正文之後添加。
這是我在數據庫視圖
current_site = get_current_site(request)
namesite = current_site.name
domain = current_site.domain
post = Post.published.get(slug=post)
profile = Profile.objects.get(id=1)
if request.method == 'POST':
comment_form = CommentForm(data=request.POST)
if comment_form.is_valid():
#create Comment object but do not say to database just yet
new_comment = comment_form.save(commit=False)
#Assigng the current post to the comment
new_comment.post = post
#save the comment to the database
new_comment.save()
comment_form = CommentForm()
else:
comment_form = CommentForm()
return render(request, 'blog/detail.html',
{'post': post, 'comments': comments,
'comment_form': comment_form, 'namesite': namesite, 'domain': domain, 'profile': profile })
我用的是|安全的過濾器,但仍然打印與上述相同。
你有什麼想法如何執行該訪問?
因此,我的意思是,我從數據庫中獲取文本,但是我沒有一張照片,我想從圖像中添加。你看到問題了嗎? –
分享你的代碼到目前爲止你已經嘗試過 –