帮忙看看这段代码那里错了

来源:3-6 实现博客数据返回页面

慕粉1901535335

2020-11-03 17:18

from django.http import HttpResponse

from blog.models import Article


def hello_world(request):

    return HttpResponse("hello world?????")


def article_content(request):
    article = Article.objects.all()[0]
    title = article.title
    brief_content = article.brief_content
    content = article.content
    article_id = article.article_id
    publish_date = article.publish_date
    return_str = 'title: %s, brief_content: %s, ' \
                 'content: %s, article_id: %s, publish_date: %s' % (title,
                                                                    brief_content,
                                                                    content,
                                                                    article_id,
                                                                    publish_date)
    return HttpResponse(return_str)

运行这段veiws.py,报错

django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.


写回答 关注

1回答

  • 不做实力派的型男不改昵称
    2020-11-10 00:02:02

    django是个框架,需要从manage.py来runserver跑服务,不然会缺少一些必要的环境变量

    view.py不能直接run的

三小时带你入门Django框架 新版上架

Python开发上手Web框架的必备课程,三小时带你入门Django框架。

25629 学习 · 248 问题

查看课程

相似问题