当我甚至没有导入它时,django无法导入httpresponseredirect

时间:2014-04-10 10:37:51

标签: python django

以下是我的观点:

from django.shortcuts import render, redirect
from tshirts.forms import TShirtUploadForm, LoginForm
from tshirts.models import TShirt
from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate, login, logout

def login(request):
    if request.method == "POST":
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username, password)

        if user is not None:
            if user.is_active():
                login(request, password)
                return redirect('tshirts.views.upload')
    else:
        form = LoginForm()

    return render(request, "tshirts/login.html", {"form":form})


@login_required
def upload(request):
    if request.method == "POST":
        form = TShirtUploadForm(request.POST, request.FILES)
        if form.is_valid():
            tshirt = TShirt()
            tshirt.title = form.cleaned_data['title']
            tshirt.search_tag_1 = form.cleaned_data['search_tag_1']
            tshirt.search_tag_2 = form.cleaned_data['search_tag_2']
            tshirt.search_tag_3 = form.cleaned_data['search_tag_2']
            tshirt.design = form.cleaned_data['design']
            tshirt.save()

            return render(request, "tshirts/upload.html", {"form" : TShirtUploadForm(),
                                                           "success" : True,})
    else:
        form = TShirtUploadForm()

    return render(request, "tshirts/upload.html", {"form" : form})

当我尝试运行服务器时,出现以下错误:

> Traceback (most recent call last):   File
> "C:/Users/Marijus/workspace/tshirtnation/manage.py", line 10, in
> <module>
>     execute_from_command_line(sys.argv)   File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
> line 399, in execute_from_command_line
>     utility.execute()   File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
> line 392, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)   File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
> line 261, in fetch_command
>     commands = get_commands()   File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
> line 107, in get_commands
>     apps = settings.INSTALLED_APPS   File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 54, in
> __getattr__
>     self._setup(name)   File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 50, in
> _setup
>     self._configure_logging()   File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 72, in
> _configure_logging
>     from django.utils.log import DEFAULT_LOGGING   File "C:\Python27\lib\site-packages\django\utils\log.py", line 7, in
> <module>
>     from django.views.debug import ExceptionReporter, get_exception_reporter_filter   File
> "C:\Python27\lib\site-packages\django\views\debug.py", line 10, in
> <module>
>     from django.http import (HttpResponse, HttpResponseServerError,   File "C:\Python27\lib\site-packages\django\http\__init__.py", line 4,
> in <module>
>     from django.http.response import (HttpResponse, StreamingHttpResponse, ImportError: cannot import name
> HttpResponseRedirect

我已尝试过调试,此错误出现在这一行:

HTTP / 初始化的.py:

from django.http.response import (HttpResponse, StreamingHttpResponse,
    CompatibleStreamingHttpResponse, HttpResponsePermanentRedirect,
    HttpResponseRedirect, HttpResponseNotModified, HttpResponseBadRequest,
    HttpResponseForbidden, HttpResponseNotFound, HttpResponseNotAllowed,
    HttpResponseGone, HttpResponseServerError, Http404, BadHeaderError)

我无法理解导致此直接导入的原因。我在这里做错了吗?

0 个答案:

没有答案