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',
],
},
},
]
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')
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??
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAJsLnpG8ZBN_15wTd9eb9S3MxZrA22w0BscZdVQQ6tkzaF4EQ%40mail.gmail.com.
<a href="/blog/index/">index</a>
There is no problem with writing this wayI don't understand why.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACp8TZhouVJF-zzJhhRGYRimrdsPG_7WvEzcTFuOKoXuR3N0%2Bg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHfGPEcumuTKs7dtdAkSobNjqbHEiRmYmjGa%3DyZKQJQ-JgdaSQ%40mail.gmail.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()
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAJsLnobXdxZUe-v8%3D2u-P5bLhwHep8yDfTM-mLuPOWeS7Ka-g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHfGPEcOkQAqR2LSDWf6%2Bzz-qBrJFzszoVBukACyh93aSa5mRA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOu2D2vBaixvBzJv2MvGBFOuMUopij7q48oiKNZxhHq4xjShuw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAJsLnpk3Z%2BTq%3DYB%2Bc7u_rY7iCyxOSYFcZ9Xrg5%2BqR%2BuHooTng%40mail.gmail.com.