首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有名为django.shortcuts的模块

没有名为django.shortcuts的模块
EN

Stack Overflow用户
提问于 2015-02-02 00:39:01
回答 1查看 3.1K关注 0票数 0

我正在创建一个Django项目,但我遇到了一个问题。在我的views.py文件中,我在Ubuntu上的Wing IDE调试器说:

代码语言:javascript
复制
File "/home/deanna/django_test/article/views.py", line 1, in <module>
from django.shortcuts import render_to_response

ImportError: No module named django.shortcuts

这是我的views.py文件:

代码语言:javascript
复制
from django.shortcuts import render_to_response
from article.models import Article
from django.http import HttpResponse
#import pdb; pdb.set_trace()
# Create your views here.

def articles(request):
    language = 'en-us'
    session_language = 'en-us'

    if 'lang' in request.COOKIES:
        language = request.COOKIES['lang']

    return render_to_response('articles.html',  
                          {'articles':
                           Article.objects.all(), 'language' : language })

def article(request, article_id=1):
    return render_to_response('article.html', {'article': 
  Article.objects.get(id=article_id)}}                                    
#The line above is supposed to be properly indented but Stack Overflow isn't letting me do that.

def language(request, language='en-us'):
    response = HttpResponse("setting language to %s" % language)


    response.set_cookie('lang', language)

    return response

当我在我的本地主机上运行网页时,我得到了这个错误:

代码语言:javascript
复制
Page not found (404)
Request Method:     GET
Request URL:    http://127.0.0.1:8000/articles/all/

Using the URLconf defined in django_test.urls, Django tried these URL  patterns, in this order:

    ^all/$
    ^get/(?P<article_id>\d+)/$
    ^language/(?P<language>[a-z\-]+)/$

The current URL, articles/all/, didn't match any of these.

You're seeing this error because you have DEBUG = True in your Django  settings file. Change that to False, and Django will display a standard 404 page.

我已经创建了一个urls.py文件和一个settings.py文件。这两个都没有错误。我还有一个articles.html和一个article.html文件,它们也没有错误。文件的文件路径:

代码语言:javascript
复制
urls.py- /home/(my name)/django_test/article
views.py- /home/(my name)/django_test/article
settings.py- /home/(my name)/django_test/django_test
articles.html- /home/(my name)/django_test/article/templates
article.html- /home/(my name)/django_test/article/templates

我将django.shortcuts下载到我的django_test文件中,但是我不知道为什么调试器会报错,也不知道为什么我的网页不能加载。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2021-01-21 18:14:58

当你面对这些类型的错误时:

代码语言:javascript
复制
ModuleNotFoundError: No module named 'django.shortscuts'

首先检查拼写是否正确:

代码语言:javascript
复制
from django.http import HttpResponse
from django.shortcuts import redirect
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28265031

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档