django 질문입니다


  • Level 4

    class IndexView(View):
    def get(self, request, *args, **kwargs):
    content_list = mainmodel.objects.order_by('id')
    community = mainmodel.objects
    author = mainmodel.author
    paginator = Paginator(content_list, 5)
    page = request.GET.get('page')
    posts = paginator.get_page(page)
    return render(request, 'main/main.html', {'community':community, 'posts':posts, 'author':author})

    def main_form(request):
    
        if request.method == 'POST':
    
            form = mainform(request.POST)
    
            if form.is_valid():
    
                post = form.save(commit=False)
    
                post.author = get_user(request)
    
                post.save()
    
                return redirect('/community')
    
            return HttpResponse('에러')
    
        elif request.method == 'GET':
    
            form = mainform()
    
            return render(request, 'main/upload-community.html', {'form':form})
    
        else:
    
            pass
    

    class mainmodel(models.Model):
    author = models.ForeignKey(User, on_delete = True, null=True)
    title = models.CharField(max_length = 50)
    explain = models.CharField(max_length = 100)
    maincontent = models.TextField(max_length = 10000)

    템플릿
    <td><a href="{% url 'detail' community.id %}">{{ author.username }}</a></td>
    이렇게 했는데 아무것도 안뜨네요
    도와주실분 구합니다ㅠㅠ

  • Level 1

    @유원정 저녁에 전 질문이랑 같이 답변해드리겠습니다!

ONLINE USERS

POPULAR TOPICS

SUGGESTED TOPICS