D
D
Dmitry2015-02-19 17:40:43
Django
Dmitry, 2015-02-19 17:40:43

Django 1.7, detailed view of the object is not displayed, I get a 404 error and the year is not specified, where to look?

Actually the question is in the title, then I enclose code listings:
settings.py

"""
Django settings for app project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'vk+0_u5-&dzaqg5p$x)s-)74=mk_d9a8#o55ke8&i#c776fvk#'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'app',
    'django_jinja',
    'contacts',
    'ckeditor',
    'crispy_forms',
    'talks',


)

CKEDITOR_UPLOAD_PATH = 'uploads'

CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': 'full',
        'height': 400,
    },
}


INSTALLED_APPS += ('django_markdown', )

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',
)

ROOT_URLCONF = 'app.urls'

WSGI_APPLICATION = 'app.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'app',  # Or path to database file if using sqlite3.The following settings are not used with sqlite3:
        'USER': 'postgres',
        'PASSWORD': 'pass',
        'HOST': 'localhost',  # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '5432', # Set to empty string for default.
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/

TIME_ZONE = 'Europe/Moscow'
LANGUAGE_CODE = 'ru-ru'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = (

    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(
        os.path.dirname(__file__),
        'static',
     ),
)

STATIC_ROOT = "/Volumes/cloud/host/django/app/static"
MEDIA_ROOT = '/Volumes/cloud/host/django/app/media'
CKEDITOR_JQUERY_URL = 'static/js/jquery.min.js'
MEDIA_URL = '/media/'
CRISPY_TEMPLATE_PACK = 'bootstrap3'
#TEMPLATE_DIRS = ('templates',)
TEMPLATE_DIRS = (os.path.join(BASE_DIR,"templates/"),)


TEMPLATE_LOADERS = (

   'django_jinja.loaders.AppLoader',
   'django_jinja.loaders.FileSystemLoader',

)

urls.py
from __future__ import absolute_import
from django.conf.urls import patterns, include, url
from . import views

#таким способом можно указать namespace для группы наших урлов
list_patterns = patterns(
    '',
    url(r'^$', views.TalkListView.as_view(), name='list'),
    url(r'^(?P<slug>[-\w]+)/$', views.TalkListDetailView.as_view(), name='detail'),
)


urlpatterns = patterns(
    '',
    url(r'^lists/', include(list_patterns, namespace='lists')),
)


#@ fixme:

views.py
from __future__ import absolute_import
#from django.http import HttpResponse
from django.views import generic
from braces import views
from talks import models


class TalkListView(
    views.LoginRequiredMixin,
    generic.ListView
):
    model = models.TalkList
    def get_queryset(self):
        return self.request.user.lists.all() #@ FIXME: не выдаёт ссылку на объект в шаблоне списка

class TalkListDetailView(
    views.LoginRequiredMixin,
    #views.PrefetchRelatedMixin,
    generic.DateDetailView
):
    model =  models.TalkList
    #prefetch_related = ('talks',)

    def get_queryset(self):
        queryset = super(TalkListDetailView)
        queryset = queryset.filter(user=self.request.user)
        return queryset

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan Luxurious, 2015-02-20
@topwebmaster

No need to use generic.DateDetailView, searches by date, not by slug

I
Ilya, 2015-02-19
@FireGM

And in a DB checked on presence of the necessary data? Maybe they don't really exist?
Or maybe you weren't logged in. Then filter(user=self.request.user) will return nothing. Or saved under the wrong user under which the authorization was.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question