Django未出现在HTML页面上

时间:2019-02-15 00:47:37

标签: html django python-3.x image web

{% extends 'Post_html/Layout.html' %}
{% include 'Add_css/arrow.html' %}
{% block body %}
<!DOCTYPE html>
<html>

   <head>
      <title>Three Column HTML Layout</title>

       <style type="text/css">
        .kolon { float:right; padding:5px; margin:5px; }

</style>

   </head>

   <body>

      <table width = "100%" border = "0">

         <tr valign = "top">
            <td width = "20%">

               <a style="margin-left:38px;" href="{% url 'help_post_urls:create_post' %}">Post Oluştur </a>
                <br />
            </td>

            <td class="container" height = "200" width = "60%">

                <!– Sayfanın akış bölümü –>

                {% for post in post_list %}

    <h3><a href="{% url 'help_post_urls:post_detail' post.pk %}">{{ post.title }} </a></h3>

                    <img src="{{ post.image_post.url }}">

    <p>{{ post.content }}</p>
    <small >Oluşturulma Tarihi : {{ post.create_post}}


        <small > Güncellenme Tarihi: {{ post.update_post|timesince }}</small></small>
                <form class="kolon" action="{% url 'help_post_urls:update_post' post.pk %}">

                        <input name="post_güncelle"  type="hidden" value="{{ post.pk }}">
                  <input class="btn btn-danger" style="height: 35px;" type="submit" value="Güncelle"> </form>

                    <form class="kolon" action="{% url 'help_post_urls:delete_post' post.pk %}">
                    {% csrf_token %}
                        <input name="post_sil" type="hidden" value="{{ post.pk }}">
                  <input class="btn btn-danger" style="height: 35px;" type="submit" value="sil">

                  </form>
                    <br>
                    <br>

    <hr>
              {% endfor %}

            </td clas>
        <table>

   </body>
</html>
{% endblock  %}

<model>

<!-- begin snippet: js hide: false console: true babel: false -->

`     从django.core.exceptions导入ObjectDoesNotExist     从django.shortcuts导入渲染,HttpResponse,HttpResponseRedirect,反向,get_object_or_404     从.post_form导入PostForm     从.models import Post_article

# Create your views here.

def index(request):
    indeks = index
    return render(request,'Post_html/index.html',context={'index':indeks})

def create_post(request):
    post_form = PostForm()

    if request.method == 'POST':
        post_form = PostForm(request.POST or None, request.FILES or None)
        if post_form.is_valid():
            created_post = post_form.save(commit=True)
            return HttpResponseRedirect(reverse('Posts:post_detail',kwargs={'pk':created_post.id}))
    return render(request,'Post_html/create_post.html',context={'form':post_form})

def post_list(request):
    posts_list = Post_article.objects.all()
    return render(request,'Post_html/post_list.html',context={'post_list':posts_list})

def update_post(request,pk):
    post = get_object_or_404(Post_article,pk=pk)
    form = PostForm(request.POST or None,request.FILES or None,instance=post)

    if form.is_valid():
        form.save(commit=True)
        return HttpResponseRedirect(reverse('help_post_urls:post_detail',kwargs={ 'pk':form.instance.id}))
    return render(request,'Post_html/update_post.html',context={'form': form})


def delete_post(request,pk):
    if request.method == 'POST':
        pk=request.POST.get('post_id',None)
        post = get_object_or_404(Post_article,pk=pk)
        post.delete()
        return HttpResponseRedirect(reverse('help_post_urls:post_list'))
    post = get_object_or_404(Post_article,pk=pk)
    post.delete()
    return HttpResponseRedirect(reverse('help_post_urls:post_list'))

def post_detail(request,pk):
    try:
        postest= Post_article.objects.get(pk=pk)
    except ObjectDoesNotExist:
        return HttpResponse('Böyle bir post bulunamadı')
    return render(request,'Post_html/post_detail.html',context={'Post_detail':postest})
from django.db import models
from PIL import ImageFile

# Create your models here.

class Categorys(models.Model):
    kategori_adi=models.CharField(max_length=80)

    def __str__(self):
        return "%s"%(self.kategori_adi)

    class Meta:
        verbose_name =" Kategori"
        verbose_name_plural="Kategori"


class Post_article(models.Model):
    author = models.ForeignKey("auth.User",on_delete= models.CASCADE)
    title = models.CharField(max_length=120,verbose_name="Başlık")
    content = models.TextField(verbose_name="İçerik")
    draft = models.BooleanField(default=False,verbose_name='Taslak Oluşturulsun mu?')
    kategori = models.ManyToManyField(Categorys,verbose_name='Kategori')
    create_post = models.DateTimeField(auto_now_add=True,verbose_name='Post oluşturulma zamanı',)
    update_post = models.DateTimeField(auto_now=True,verbose_name='Post güncelleme zamanı')
    image_post = models.ImageField(blank=True,verbose_name="Fotoğraf yükle")

    def __str__(self):
        return "%s"%(self.title)

    class Meta:
        verbose_name_plural = 'Gönderi'
        verbose_name = 'Gönderi'
        ordering = ['-create_post']

Django没有出现在HTML页面上,我检查了所有内容,我认为这是一个技术问题。我不得不问,因为我不能使其合理化。

0 个答案:

没有答案