Answer the question
In order to leave comments, you need to log in
How to solve a problem with Django admin?
AttributeError at /admin/ 'module' object has no attribute 'rindex'
The problem occurs only when trying to go to the admin page 127.0.0.1:8000/admin/
I can’t say for sure after what the problem appeared, but I noticed after I added a new module .
Trace:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.8.3
Python Version: 3.4.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
'photo',
'news',
'announce',
'contact',
'chief',
'birthday',
'bc')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')
Traceback:
File "C:\Python34\lib\site-packages\django-1.8.3-py3.4.egg\django\core\handlers\base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python34\lib\site-packages\django-1.8.3-py3.4.egg\django\contrib\admin\sites.py" in wrapper
254. return self.admin_view(view, cacheable)(*args, **kwargs)
File "C:\Python34\lib\site-packages\django-1.8.3-py3.4.egg\django\utils\decorators.py" in _wrapped_view
110. response = view_func(request, *args, **kwargs)
File "C:\Python34\lib\site-packages\django-1.8.3-py3.4.egg\django\views\decorators\cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "C:\Python34\lib\site-packages\django-1.8.3-py3.4.egg\django\contrib\admin\sites.py" in inner
223. if request.path == reverse('admin:logout', current_app=self.name):
File "C:\Python34\lib\site-packages\django-1.8.3-py3.4.egg\django\core\urlresolvers.py" in reverse
550. app_list = resolver.app_dict[ns]
File "C:\Python34\lib\site-packages\django-1.8.3-py3.4.egg\django\core\urlresolvers.py" in app_dict
352. self._populate()
File "C:\Python34\lib\site-packages\django-1.8.3-py3.4.egg\django\core\urlresolvers.py" in _populate
308. for name in pattern.reverse_dict:
File "C:\Python34\lib\site-packages\django-1.8.3-py3.4.egg\django\core\urlresolvers.py" in reverse_dict
338. self._populate()
File "C:\Python34\lib\site-packages\django-1.8.3-py3.4.egg\django\core\urlresolvers.py" in _populate
326. lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args))
File "C:\Python34\lib\site-packages\django-1.8.3-py3.4.egg\django\core\urlresolvers.py" in callback
247. self._callback = get_callable(self._callback_str)
File "C:\Python34\lib\functools.py" in wrapper
448. result = user_function(*args, **kwds)
File "C:\Python34\lib\site-packages\django-1.8.3-py3.4.egg\django\core\urlresolvers.py" in get_callable
96. mod_name, func_name = get_mod_func(lookup_view)
File "C:\Python34\lib\site-packages\django-1.8.3-py3.4.egg\django\core\urlresolvers.py" in get_mod_func
159. dot = callback.rindex('.')
Exception Type: AttributeError at /admin/
Exception Value: 'module' object has no attribute 'rindex'
from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns, static
from django.conf.urls.static import static
from khm.settings import *
from main.views import *
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^photo/', include("photo.urls")),
url(r'^news/', include("news.urls")),
url(r'^announce/', include("announce.urls")),
url(r'^contact/', include("contact.urls")),
url(r'^chief/', include("chief.urls")),
url(r'^birthday/', include("birthday.urls")),
url(r'^bc/', include("bc.urls")),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()
urlpatterns += url(r'^', include("main.urls")),
from django.conf.urls import include, url
from birthday.views import *
urlpatterns = [
url(r'^', bthd, name="bthd"),
]
from django.db import models
class Birthday(models.Model):
name = models.CharField(max_length=256, verbose_name="ФИО", null=True, blank=True)
dob = models.DateField()
pn = models.IntegerField(verbose_name="Порядковый номер", null=True, blank=True)
photo = models.ImageField(upload_to='birthday/photo',verbose_name="Фото",
blank=False, null=False, default='birthday/photo/photo.jpg')
def __str__(self):
return self.name
class Meta():
db_table = "Дни рождения"
verbose_name = "Дни рождения"
from django.contrib import admin
from birthday.models import *
from birthday.views import *
class Birthday_admin(admin.ModelAdmin):
fields = ('name', 'dob', 'pn', 'photo',)
ordering = ('-dob',)
list_display = ('name', 'dob')
admin.site.register(Birthday, Birthday_admin)
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
'photo',
'news',
'announce',
'contact',
'chief',
'birthday',
'bc',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'khm.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['C:/Python34/khm/main/template',
'C:/Python34/khm/photo/template',
'C:/Python34/khm/announce/template',
'C:/Python34/khm/news/template',
'C:/Python34/khm/contact/template',
'C:/Python34/khm/chief/template',
'C:/Python34/khm/birthday/template',
'C:/Python34/khm/bc/template',
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.media',
'django.core.context_processors.media',
],
},
},
]
WSGI_APPLICATION = 'khm.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
LANGUAGE_CODE = 'ru-ru'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')
MEDIA_URL = '/uploads/'
LOGIN_URL = "login"
LOGOUT_URL = "logout"
LOGIN_REDIRECT_URL = "/"
LOGOUT_URL_REDIRECT_URL = "/"
AUTH_USER_MODEL = 'main.AuthUser'
from django.shortcuts import render, render_to_response, redirect
from django.template import RequestContext
from birthday.models import *
from datetime import date
#today = date.today()
def bthd(request):
args = {}
return render_to_response("bd.html", args, context_instance=RequestContext(request))
"""
args['birthdays'] = Birthday.objects.order_by('-dob')
if Birthday.objects.get(dob=today):
args['bd_today'] = Birthday.objects.get(dob=today)
args['birthdays'] = Birthday.objects.order_by('-dob')
return render_to_response("bd.html", args, context_instance=RequestContext(request))
else:
args['birthdays'] = Birthday.objects.order_by('-dob')
return render_to_response("bd.html", args, context_instance=RequestContext(request))
"""
Answer the question
In order to leave comments, you need to log in
from django.conf.urls import include, url
from birthday.views import *
urlpatterns = [
url(r'^', bthd, name="bthd"),
]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question