Can someone help me??

48 views
Skip to first unread message

Hella Nick

unread,
Jul 1, 2020, 4:30:55 AM7/1/20
to Django users
Can someone help me??


My project catalogue: 


My setttings:
TEMPLATES = [
   
{
       
'BACKEND': 'django.template.backends.django.DjangoTemplates',
       
'DIRS': [os.path.join(BASE_DIR, 'blog/templates/')]
       
,
       
'APP_DIRS': True,
       
'OPTIONS': {
           
'context_processors': [
               
'django.template.context_processors.debug',
               
'django.template.context_processors.request',
               
'django.contrib.auth.context_processors.auth',
               
'django.contrib.messages.context_processors.messages',
           
],
       
},
   
},
]

My views:
from django.shortcuts import render,HttpResponse
from django.views.generic import View
from blog.tool.IPs import volume
from blog.models import Article

class index(View):
    def get(self,request):
        volume(request)
 

        return render(request,'index.html')

Error:


Internal Server Error: /blog/index/
Traceback (most recent call last):
  File "D:\Python3\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "D:\Python3\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "D:\Python3\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "D:\Python3\lib\site-packages\django\views\generic\base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "D:\Python3\lib\site-packages\django\views\generic\base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "D:\pythonwork\blog\personBlog\blog\views\index.py", line 25, in get
    return render(request,'index.html',locals())
  File "D:\Python3\lib\site-packages\django\shortcuts.py", line 36, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "D:\Python3\lib\site-packages\django\template\loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "D:\Python3\lib\site-packages\django\template\backends\django.py", line 61, in render
    return self.template.render(context)
  File "D:\Python3\lib\site-packages\django\template\base.py", line 171, in render
    return self._render(context)
  File "D:\Python3\lib\site-packages\django\template\base.py", line 163, in _render
    return self.nodelist.render(context)
  File "D:\Python3\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "D:\Python3\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "D:\Python3\lib\site-packages\django\template\defaulttags.py", line 442, in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
  File "D:\Python3\lib\site-packages\django\urls\base.py", line 58, in reverse
    app_list = resolver.app_dict[ns]
  File "D:\Python3\lib\site-packages\django\urls\resolvers.py", line 477, in app_dict
    self._populate()
  File "D:\Python3\lib\site-packages\django\urls\resolvers.py", line 430, in _populate
    url_pattern._populate()
  File "D:\Python3\lib\site-packages\django\urls\resolvers.py", line 418, in _populate
    self._callback_strs.add(url_pattern.lookup_str)
  File "D:\Python3\lib\site-packages\django\utils\functional.py", line 37, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "D:\Python3\lib\site-packages\django\urls\resolvers.py", line 360, in lookup_str
    return callback.__module__ + "." + callback.__qualname__
TypeError: unsupported operand type(s) for +: 'ModelBase' and 'str'

  • Can someone help me??



oba stephen

unread,
Jul 1, 2020, 5:04:59 AM7/1/20
to django...@googlegroups.com
The Error is straight forward, you are using an operand "+" for two two data types that it can't be used on. This might be from your "volume" function. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/840576c0-ef86-46ea-b35c-8a3708f7460bo%40googlegroups.com.

Sencer Hamarat

unread,
Jul 1, 2020, 5:14:18 AM7/1/20
to django...@googlegroups.com
File "D:\pythonwork\blog\personBlog\blog\views\index.py", line 25, in get
    return render(request,'index.html',locals())

According to this line in that error seems to have occurred while rendering.
There is at least one "+" operation in "index.html" or "local()" method call.
You have to check data types where the "+" operator used.
And also according to the error itself, the one of that value is not a string.
I think the "ModelBase" model has no '__str__'.

Saygılarımla,
Sencer HAMARAT



Hella Nick

unread,
Jul 1, 2020, 10:52:20 PM7/1/20
to django...@googlegroups.com
Dear  Sencer:
    
  <a href="/blog/index/">index</a>

 
  •       There is no problem with writing this wayI don't understand why.


Thank You

Sencer Hamarat <sencer...@gmail.com> 于2020年7月1日周三 下午5:13写道:

Hella Nick

unread,
Jul 1, 2020, 10:57:00 PM7/1/20
to django...@googlegroups.com
Dear  Mir  oba stephen:

     I deleted  "volume" function,But The result is the same.

Hella Nick <perso...@gmail.com> 于2020年7月2日周四 上午10:51写道:

oba stephen

unread,
Jul 2, 2020, 2:28:58 AM7/2/20
to django...@googlegroups.com
Can you share your models.py?

Like Sencer said you have to check data types where the "+" operator is used.

Hella Nick

unread,
Jul 2, 2020, 2:32:34 AM7/2/20
to django...@googlegroups.com
class Article(models.Model):
# time = datetime.datetime.now()
IMG_LINK = '/static/images/summary.jpg'
id = models.AutoField(primary_key=True,verbose_name='自增主键')
title = models.CharField(verbose_name='文章标题',max_length=100)
intro = models.CharField(max_length=300,verbose_name='文章摘要')
content = MDTextField(verbose_name='文章正文')
img_link = models.CharField('图片地址', default=IMG_LINK, max_length=255)
addtime = models.DateTimeField(verbose_name='发布时间',auto_now =True)
updatetime = models.DateTimeField(verbose_name='修改时间', auto_now=True)
number = models.IntegerField(verbose_name='阅读量',default=0)
loves = models.IntegerField(verbose_name='点赞',default=0)
keywords = models.CharField(max_length=120,verbose_name='文章关键词',)
sort = models.ForeignKey('Sort',to_field='id',on_delete=models.CASCADE,verbose_name='分类外键')
member = models.OneToOneField(User,on_delete=models.CASCADE,related_name='profile',verbose_name='用户一对多外键')

class Mate:
verbose_name = '文章'
verbose_name_plural = verbose_name
ordering = ['-updatetime']

def __str__(self):
return self.title[:20]

# def get_absolute_url(self):
# return reversed('blog:article',kwargs={'sulg':self.id})
# return reverse('blog:detail', kwargs={'pk':self.id})

def body_to_markdown(self):
return markdown.markdown(self.content.replace("\r\n", ' \n'),extensions=[
'markdown.extensions.extra',
'markdown.extensions.codehilite',
'markdown.extensions.toc',
],safe_mode=True,enable_attributes = False)

def update_view(self):
self.number += 1
self.save(update_fields=['number'])

def get_pre(self):
return Article.objects.filter(id__lt=self.id).order_by('-id').first()

def get_next(self):
return Article.objects.filter(id__gt=self.id).order_by('id').first()

oba stephen <obast...@gmail.com> 于2020年7月2日周四 下午2:28写道:

Mohammed Alnajdi

unread,
Jul 2, 2020, 2:41:51 AM7/2/20
to django...@googlegroups.com
The error seems to be somewhere in the Urls

I think it might be issue with
"{% url 'blog:index/' %}"

try to remove the slash
"{% url 'blog:index' %}"

you might need to do the same with other urls


oba stephen

unread,
Jul 2, 2020, 2:49:31 AM7/2/20
to django...@googlegroups.com
I don't see anything wrong with the Models.py file, I think you should try removing those slash "/" just as Mohammed said.

Hella Nick

unread,
Jul 2, 2020, 2:59:25 AM7/2/20
to django...@googlegroups.com
Thank you Oba Stephen and Mohammed Alnajdi.
I think this is a real BUG.
I'm ready to rebuild the project.
Thank you again.

oba stephen <obast...@gmail.com> 于2020年7月2日周四 下午2:48写道:
Reply all
Reply to author
Forward
0 new messages