Answer the question
In order to leave comments, you need to log in
Can only concatenate str (not "NoneType") to str in Django, what's wrong?
from django.shortcuts import render
from django.http import HttpResponse
from .models import Board
# Create your views here.
def index(request):
s = 'СМР Блог\r\n\r\n\r\n'
for b in Board.objects.order_by('-published'):
s += b.title + '\r\n' + b.content + '\r\n'
return HttpResponse(s, content_type = 'text/plain; charset = utf-8')
from django.urls import path
from .views import index
urlpatterns = [
path('board/', index)#, name = 'index')
]
from django.db import models
# Create your models here.
class Board(models.Model):
title = models.CharField(max_length = 120)
content = models.TextField(max_length = 6000)
published = models.DateTimeField(auto_now_add = True, db_index = True)
TypeError: can only concatenate str (not "NoneType") to str
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question