Differences between revisions 1 and 4 (spanning 3 versions)
Revision 1 as of 2007-02-26 16:04:14
Size: 13664
Editor: 211
Comment:
Revision 4 as of 2007-02-27 15:23:38
Size: 6479
Editor: 222
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
----
구글링 결과 다음과 같은 URL을 찾을수 있었습니다
http://www.nabble.com/'function'-object-has-no-attribute-'rindex'-t2884548.html
영어가 짧아 대략 읽어본 바로는 최신버전의 django를 사용해달라라는것 같은데
0.95.1버전이 최신버전 아닌가요?
Line 32: Line 37:
Traceback (innermost last)
Switch to copy-and-paste view

    * /usr/lib/python2.4/site-packages/Django-0.95.1-py2.4.egg/django/core/handlers/base.py in get_response
        58. for middleware_method in self._request_middleware:
        59. response = middleware_method(request)
        60. if response:
        61. return response
        62.
        63. resolver = urlresolvers.RegexURLResolver(r'^/', settings.ROOT_URLCONF)
        64. try:
        65. callback, callback_args, callback_kwargs = resolver.resolve(path) ...
        66.
        67. # Apply view middleware
        68. for middleware_method in self._view_middleware:
        69. response = middleware_method(request, callback, callback_args, callback_kwargs)
        70. if response:
        71. return response
      ▶ Local vars
      Variable Value
      exceptions
      <module 'django.core.exceptions' from '/usr/lib/python2.4/site-packages/Django-0.95.1-py2.4.egg/django/core/exceptions.pyc'>
      mail_admins
      <function mail_admins at 0xb6daa8ec>
      middleware_method
      <bound method AuthenticationMiddleware.process_request of <django.contrib.auth.middleware.AuthenticationMiddleware object at 0xb6dabc6c>>
      path
      '/test/'
      request
      <WSGIRequest GET:<MultiValueDict: {}>, POST:<MultiValueDict: {}>, COOKIES:{'sessionid': '354fed1fb48f42ce4f5ce89f301ed501'}, META:{'COLORTERM': 'gnome-terminal', 'CONTENT_LENGTH': '', 'CONTENT_TYPE': 'text/plain', 'DBUS_SESSION_BUS_ADDRESS': 'unix:abstract=/tmp/dbus-Y1yu84SphQ,guid=d173e2459cd85c7e3601c600dd012f00', 'DESKTOP_SESSION': 'default', 'DESKTOP_STARTUP_ID': '', 'DISPLAY': ':0.0', 'DJANGO_SETTINGS_MODULE': 'test2.settings', 'GATEWAY_INTERFACE': 'CGI/1.1', 'GDMSESSION': 'default', 'GDM_XSERVER_LOCATION': 'local', 'GNOME_DESKTOP_SESSION_ID': 'Default', 'GNOME_KEYRING_SOCKET': '/tmp/keyring-GemmVy/socket', 'GTK_IM_MODULE': 'scim', 'GTK_RC_FILES': '/etc/gtk/gtkrc:/home/athxue/.gtkrc-1.2-gnome2', 'HISTCONTROL': 'ignoredups', 'HOME': '/home/athxue', 'HTTP_ACCEPT': 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5', 'HTTP_ACCEPT_CHARSET': 'EUC-KR,utf-8;q=0.7,*;q=0.7', 'HTTP_ACCEPT_ENCODING': 'gzip,deflate', 'HTTP_ACCEPT_LANGUAGE': 'ko-kr,ko;q=0.8,en-us;q=0.5,en;q=0.3', 'HTTP_CACHE_CONTROL': 'max-age=0', 'HTTP_CONNECTION': 'keep-alive', 'HTTP_COOKIE': 'sessionid=354fed1fb48f42ce4f5ce89f301ed501', 'HTTP_HOST': '127.0.0.1:8000', 'HTTP_KEEP_ALIVE': '300', 'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; U; Linux i686; ko-KR; rv:1.8.1.1) Gecko/20060601 Firefox/2.0.0.1 (Ubuntu-edgy)', 'LANG': 'ko_KR.UTF-8', 'LESSCLOSE': '/usr/bin/lesspipe %s %s', 'LESSOPEN': '| /usr/bin/lesspipe %s', 'LOGNAME': 'athxue', 'LS_COLORS': 'no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.flac=01;35:*.mp3=01;35:*.mpc=01;35:*.ogg=01;35:*.wav=01;35:', 'OLDPWD': '/home/athxue', 'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games', 'PATH_INFO': '/test/', 'PWD': '/home/athxue/django-test/test2', 'QT_IM_MODULE': 'scim', 'QUERY_STRING': '', 'REMOTE_ADDR': '127.0.0.1', 'REMOTE_HOST': 'localhost', 'REQUEST_METHOD': 'GET', 'RUN_MAIN': 'true', 'SCRIPT_NAME': '', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8000', 'SERVER_PROTOCOL': 'HTTP/1.1', 'SERVER_SOFTWARE': 'WSGIServer/0.1 Python/2.4.4c1', 'SESSION_MANAGER': 'local/athxue-desktop:/tmp/.ICE-unix/4254', 'SHELL': '/bin/bash', 'SHLVL': '1', 'SSH_AGENT_PID': '4395', 'SSH_AUTH_SOCK': '/tmp/ssh-yGWBkV4254/agent.4254', 'TERM': 'xterm', 'TZ': 'America/Chicago', 'USER': 'athxue', 'USERNAME': 'athxue', 'WINDOWID': '41945821', 'XAUTHORITY': '/home/athxue/.Xauthority', 'XMODIFIERS': '@im=SCIM', '_': '/usr/bin/python', 'wsgi.errors': <open file '<stderr>', mode 'w' at 0xb7d6a0b0>, 'wsgi.file_wrapper': <class 'django.core.servers.basehttp.FileWrapper'>, 'wsgi.input': <socket._fileobject object at 0xb6e18dbc>, 'wsgi.multiprocess': False, 'wsgi.multithread': True, 'wsgi.run_once': False, 'wsgi.url_scheme': 'http', 'wsgi.version': (1, 0)}>
      resolver
      <django.core.urlresolvers.RegexURLResolver object at 0xb6dabd4c>
      response
      None
      self
      <django.core.handlers.wsgi.WSGIHandler object at 0xb79b590c>
      settings
      <django.conf.LazySettings object at 0xb7c7280c>
      urlresolvers
      <module 'django.core.urlresolvers' from '/usr/lib/python2.4/site-packages/Django-0.95.1-py2.4.egg/django/core/urlresolvers.pyc'>
    * /usr/lib/python2.4/site-packages/Django-0.95.1-py2.4.egg/django/core/urlresolvers.py in resolve
       140. def resolve(self, path):
       141. tried = []
       142. match = self.regex.search(path)
       143. if match:
       144. new_path = path[match.end():]
       145. for pattern in self.urlconf_module.urlpatterns:
       146. try:
       147. sub_match = pattern.resolve(new_path) ...
       148. except Resolver404, e:
       149. tried.extend([(pattern.regex.pattern + ' ' + t) for t in e.args[0]['tried']])
       150. else:
       151. if sub_match:
       152. return sub_match[0], sub_match[1], dict(match.groupdict(), **sub_match[2])
       153. tried.append(pattern.regex.pattern)
      ▶ Local vars
      Variable Value
      match
      <_sre.SRE_Match object at 0xb6db0e58>
      new_path
      'test/'
      path
      '/test/'
      pattern
      <django.core.urlresolvers.RegexURLPattern object at 0xb6db2c0c>
      self
      <django.core.urlresolvers.RegexURLResolver object at 0xb6dabd4c>
      sub_match
      None
      tried
      ['^admin/']
    * /usr/lib/python2.4/site-packages/Django-0.95.1-py2.4.egg/django/core/urlresolvers.py in resolve
       105. args = match.groups()
       106. # In both cases, pass any extra_kwargs as **kwargs.
       107. kwargs.update(self.default_args)
       108.
       109. try: # Lazily load self.func.
       110. return self.func, args, kwargs
       111. except AttributeError:
       112. self.func = self.get_callback() ...
       113. return self.func, args, kwargs
       114.
       115. def get_callback(self):
       116. mod_name, func_name = get_mod_func(self.callback)
       117. try:
       118. return getattr(__import__(mod_name, '', '', ['']), func_name)
      ▶ Local vars
      Variable Value
      args
      ()
      kwargs
      {}
      match
      <_sre.SRE_Match object at 0xb6d5bb80>
      path
      'test/'
      self
      <django.core.urlresolvers.RegexURLPattern object at 0xb6db2c0c>
    * /usr/lib/python2.4/site-packages/Django-0.95.1-py2.4.egg/django/core/urlresolvers.py in get_callback
       109. try: # Lazily load self.func.
       110. return self.func, args, kwargs
       111. except AttributeError:
       112. self.func = self.get_callback()
       113. return self.func, args, kwargs
       114.
       115. def get_callback(self):
       116. mod_name, func_name = get_mod_func(self.callback) ...
       117. try:
       118. return getattr(__import__(mod_name, '', '', ['']), func_name)
       119. except ImportError, e:
       120. raise ViewDoesNotExist, "Could not import %s. Error was: %s" % (mod_name, str(e))
       121. except AttributeError, e:
       122. raise ViewDoesNotExist, "Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e))
      ▶ Local vars
      Variable Value
      self
      <django.core.urlresolvers.RegexURLPattern object at 0xb6db2c0c>
    * /usr/lib/python2.4/site-packages/Django-0.95.1-py2.4.egg/django/core/urlresolvers.py in get_mod_func
        16.
        17. class NoReverseMatch(Exception):
        18. pass
        19.
        20. def get_mod_func(callback):
        21. # Converts 'django.views.news.stories.story_detail' to
        22. # ['django.views.news.stories', 'story_detail']
        23. dot = callback.rindex('.') ...
        24. return callback[:dot], callback[dot+1:]
        25.
        26. def reverse_helper(regex, *args, **kwargs):
        27. """
        28. Does a "reverse" lookup -- returns the URL for the given args/kwargs.
        29. The args/kwargs are applied to the given compiled regular expression.
      ▶ Local vars
Line 169: Line 41:

작은 따옴표를 제거했는데 이제는 이런 에러가 나오네요. 이런 문제가 생겼을때 질문할 수 있는곳이 있다는게 너무 감사할 따름입니다. 수고 하시고요. yong27님 파이썬광장에서의 사진은 꽤 인상적이었습니다.^^

{{{
AttributeError at /test/
'function' object has no attribute 'rindex'
Request Method: GET
Request URL: http://127.0.0.1:8000/test/
Exception Type: AttributeError
Exception Value: 'function' object has no attribute 'rindex'
Exception Location: /usr/lib/python2.4/site-packages/Django-0.95.1-py2.4.egg/django/core/urlresolvers.py in get_mod_func, line 23
}}}
 
 ''테스트해본 결과, 제 컴퓨터에서는 아무 이상없이 잘 동작했습니다. 다음의 순서대로 했어요.'' -- ["yong27"] [[DateTime(2007-02-27T04:55:37Z)]]
 {{{
C:\work> \python25\lib\site-packages\django\bin\django-admin.py startproject django-test
C:\work> cd django-test
C:\work> gvim urls.py # 윗소스대로 수정
C:\work> gvim settings.py # 윗소스만수정하면 template 경로를 못찾는다고 나옵니다. 그래서 ,TEMPLATE_DIRS에 해당경로를 추가합니다.
C:\work> manage.py runserver # 이후, 웹브라우저에서 보면 잘 보입니다.
}}}

[Django] 질문 및 답변


구글링 결과 다음과 같은 URL을 찾을수 있었습니다 http://www.nabble.com/'function'-object-has-no-attribute-'rindex'-t2884548.html 영어가 짧아 대략 읽어본 바로는 최신버전의 django를 사용해달라라는것 같은데 0.95.1버전이 최신버전 아닌가요?

프로젝트 생성시 가장 상단에 자동으로 생성되는 urls.py를 다음과 같이 고치고 테스트 했는데 다음과 같은 에러가 나옵니다.

Toggle line numbers
   1 from django.conf.urls.defaults import *
   2 import datetime
   3 from django.shortcuts import render_to_response
   4 
   5 def current_datetime(request):
   6     now = datetime.datetime.now()
   7     return render_to_response('current_datetime.html', {'current_date': now})
   8 
   9 urlpatterns = patterns('',
  10     # Example:
  11     # (r'^test2/', include('test2.apps.foo.urls.foo')),
  12 
  13     # Uncomment this for admin:
  14     (r'^admin/', include('django.contrib.admin.urls')),
  15     (r'^test/', 'current_datetime'),
  16 )

ValueError at /test/
substring not found
Request Method:         GET
Request URL:    http://127.0.0.1:8000/test/
Exception Type:         ValueError
Exception Value:        substring not found
Exception Location:     /usr/lib/python2.4/site-packages/Django-0.95.1-py2.4.egg/django/core/urlresolvers.py in get_mod_func, line 23

substring에러라는데 어떤 에러인가요?

작은 따옴표를 제거했는데 이제는 이런 에러가 나오네요. 이런 문제가 생겼을때 질문할 수 있는곳이 있다는게 너무 감사할 따름입니다. 수고 하시고요. yong27님 파이썬광장에서의 사진은 꽤 인상적이었습니다.

AttributeError at /test/
'function' object has no attribute 'rindex'
Request Method:         GET
Request URL:    http://127.0.0.1:8000/test/
Exception Type:         AttributeError
Exception Value:        'function' object has no attribute 'rindex'
Exception Location:     /usr/lib/python2.4/site-packages/Django-0.95.1-py2.4.egg/django/core/urlresolvers.py in get_mod_func, line 23
  • 테스트해본 결과, 제 컴퓨터에서는 아무 이상없이 잘 동작했습니다. 다음의 순서대로 했어요. -- ["yong27"] DateTime(2007-02-27T04:55:37Z)

    C:\work> \python25\lib\site-packages\django\bin\django-admin.py startproject django-test
    C:\work> cd django-test
    C:\work> gvim urls.py  # 윗소스대로 수정
    C:\work> gvim settings.py  # 윗소스만수정하면 template 경로를 못찾는다고 나옵니다. 그래서 ,TEMPLATE_DIRS에 해당경로를 추가합니다.
    C:\work> manage.py runserver  # 이후, 웹브라우저에서 보면 잘 보입니다.


인실리코젠이 장고 확산에 일등공신이라는 느낌이 듭니다. 앞으로 장고에 대해 세미나 혹은 강좌를 계획하고 계신것이 있나요?

  • 감사합니다. 특별하게 준비하는 강좌는 없지만, 조만간에 뭔가 나오긴 할 듯 합니다. -- ["yong27"] DateTime(2007-02-26T05:20:48Z)


admin시스템을 사용하려고 설정을 하고 로그인을 했는데 다음과 같은 에러를 만났습니다

ProgrammingError at /admin/
(1146, "Table 'django_test.django_admin_log' doesn't exist")
Request Method:         GET
Request URL:    http://127.0.0.1:8000/admin/
Exception Type:         ProgrammingError
Exception Value:        (1146, "Table 'django_test.django_admin_log' doesn't exist")
Exception Location:     /usr/lib/python2.4/site-packages/MySQLdb/connections.py in defaulterrorhandler, line 35
Template error

In template /usr/lib/python2.4/site-packages/Django-0.95.1-py2.4.egg/django/contrib/admin/templates/admin/index.html, error at line 56

어떤 문제 때문인가요?


계속 장고에 대해 질문하게 되네요 장고를 학습하기가 여의치 않습니다. django book과 공식 홈페이지의 문서를 참조중인데 완전히 독립된 [MVC]에 적응이 잘 안되네요. 어떻게 하면 장고를 효과적으로 학습할수 있을까요?

  • 일단 Django를 자유롭게 쓰시려면 [Python]에 익숙해지셔야 합니다. 따로 시간을 내셔서라도 [Python] 사용법을 완전히 익히시고요, [Django] 홈페이지의 튜토리얼을 몇번 그대로 따라하시면 웬만큼 하실 수 있을 듯 합니다. 그 다음에는 직접 자신만의 프로젝트를 하나 해보시기를 추천합니다. 마땅한 프로젝트가 없으시면, EnglishStudyWithDjango 프로젝트를 같이 하셔도 됩니다. 가장 효과적인 학습방법은 직접 무언가를 만들면서, 접해보는 것이라고 생각합니다. -- ["yong27"] DateTime(2007-02-12T01:51:52Z)


Django기반으로된 게시판 혹은 블로그가 있을까요?

  • 아직 국내사용자가 많지 않아서, 국내서 개발된 것은 거의 없는 듯 합니다. [Google]서 검색해보면, 몇 개 정도 눈에 띄긴 하는데, 정식 패키지로 나와있기 보다는, 개별적으로 커스터마이징해서 쓰는 듯 합니다. http://code.djangoproject.com/wiki/DjangoPoweredSites 페이지를 보시면, [Django]를 쓰는 많은 사이트들을 볼 수 있습니다. -- ["yong27"] DateTime(2007-02-11T04:08:33Z)


PHP로만 웹개발을 한지 6개월 된것 같습니다. 사실 PHP는 웹 개발을 위한 스크립트의 형식이 강해 본인의 의지에 의하지 않으면 스파게티코드 가 될수밖에 없는 구조를 가지고 있다고 생각됩니다. 그래서 요즘 체계적인 개발과 반복적인 작업을 줄이기 위한 방편으로 프레임워크를 알아보 다 Django를 찾게 되었습니다. 그러나 궁금한 점은 Django를 통해 원하는 개발을 모두 할 수 있는지 입니다. 예를 들어 쇼핑몰을 개발한다던가, 단순한 홈페이지 형식이 아닌 웹 어플리케이션([ERP]등등)이 가능하냐는 것입니다.

  • 물론 모두 가능합니다. [Django]가 원래 쇼핑몰같은 웹어플리케이션 같은 것들을 개발하려고 만들어진 것입니다. 최근의 웹기술들(예를 들어, [AJAX]등)도 모두 Django에서 구현이 가능합니다. -- ["yong27"] DateTime(2007-02-10T01:21:00Z)

Django/QnA (last edited 2011-08-03 11:00:49 by localhost)

web biohackers.net