我尝试使用python django模块构建一个Web应用程序。任务是如果任何人转到链接,它将处理具有阈值的图像并保存到服务器文件夹。
我的代码是(views.py): -
from django.http import HttpResponse
import numpy as np
import cv2
import Image
from PIL import Image
import tesseract
import ctypes
import os
import ImageDraw
def index(request):
im_gray = cv2.imread('Rimage.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE)
(thresh, im_bw) = cv2.threshold(im_gray, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
thresh = 100
im_bw = cv2.threshold(im_gray, thresh, 255, cv2.THRESH_BINARY)[1]
cv2.imwrite('bw_image.png', im_bw)
return HttpResponse("Hello, world. You're at the polls index.")
此代码无法正常运行错误: -
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
98. resolver_match = resolver.resolve(request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
343. for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
372. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
366. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
File "/home/meraj/Desktop/project/web/mysite/mysite/urls.py" in <module>
5. url(r'^polls/', include('polls.urls')),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py" in include
28. urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
File "/home/meraj/Desktop/project/web/mysite/polls/urls.py" in <module>
3. from polls import views
Exception Type: IndentationError at /polls/
Exception Value: unindent does not match any outer indentation level (views.py, line 20)
我的代码没有任何问题,因为它在本地执行,但是当我尝试使用django框架时,它无法正常工作。我正朝着正确的方向前进吗?我是python web框架的新手,所以我对此没有任何想法。提前谢谢
答案 0 :(得分:1)
&#34;本地与django框架&#34;。
这是否意味着您在一台计算机上进行编辑并将文件复制到另一台计算机上?问题是IndentationEror,根据你的输出,所以这可能是一个空格/制表符或换行问题(一个窗口/一个linux?)如果是前者,尝试用编辑器中的空格替换所有选项卡并确保缩进正确后。如果是后者,请在文件上尝试dos2unix。