Could any one help me to figure out why ?
I just followed the structure of tutorial , and installed the package called django-polls to my project called mysite successfully. But it returned "TemplateDoesNotExist at /polls/" after running the server.
Following is What I have done:
1.pip install /django-polls/dist/django-polls-0.1.tar.gz
2.modifed the settings.py in mysite project
3.modifed the urls.py in mysite project
4.python manage.py runserver
settings.py in mysite project:
...
TEMPLATE_DEBUG = True
...
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
)
...
ROOT_URLCONF = 'mysite.urls'
...
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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',
],
},
},
]
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader', # <--
)
Related
i'm getting a "simple" trouble when I try to add AUTH_USER_MODEL constant to settings.py. It returns this error, but when I look to INSTALLED_APPS the app name that I'm still working is there. Here it is:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'PMEapp',
]
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
BASE_DIR = Path(__file__).resolve().parent.parent
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',
'PMEapp',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'SOSpme.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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',
],
},
},
]
WSGI_APPLICATION = 'SOSpme.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
STATIC_URL = 'static/'
MEDIA_URL = "imgs/"
MEDIA_ROOT = os.path.join(BASE_DIR, "imgs")
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static/"),
)
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
LOGIN_URL = "login"
LOGIN_REDIRECT_URL = ""
LOGOUT_REDIRECT_URL = "login"
DATE_INPUT_FORMATS = ('%d/%m/%Y','%d-%m-%Y','%Y-%m-%d')
AUTH_USER_MODEL = "PMEapp.User"
This is the error:
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'PMEapp.User' that has not been installed
My installed apps
My file system
The user model -> It is in models.py
These are the things I've tried to solve the problem:
1-Created a User file including all user types in PMEapp folder with user inside didn't work.
2-Moved User file to a folder called User, got the same error.
3-Put all user types in models.py but User(AbstractUser) was still in User.py . Didn't worked too.
4-I've added a User.py file in models folder and imported it to the file that got all the user types. Same error.
It looks like you forgot to add an init.py file to your models directory. Try adding that and startup your Django server again. You might need to import your models in your init file, like from .models import User
I have done all the necessary settings in settings.py, and i have set the urls too i the urls.py file. Each time i am trying to access /accconts/login, it will say the url did not match any pattern, and it redirects me to /accounts/profile.
This are the code
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'core'
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'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',
],
},
},
]
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
SITE_ID = 1
urlpatterns = [
path('accounts/', include('allauth.urls'))
]
Thanks for the reply. I was able to solve the problem. The way allauth works you must not be logged in while accessing /accounts/login.
What i did was to go to /accounts/logout/ and then logout before the /accounts/login will go
By default django-allauth divert logged in users from the login page.
You can use a couple of settings to fix the issue :
SET the ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS to FALSE
or
SET LOGIN_REDIRECT_URL to 'the desired path' for logged in users in the settings.py file.
https://django-allauth.readthedocs.io/en/latest/configuration.html
I created a templates directory in my django project and then created fun directory inside of which i have fun.html file.In order to access this file i have the following code in my views.py:
from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import render_to_response
def index(request):
template_name = 1
return render(request,'fun/fun.html')
and here is the directory of my project:enter image description here
I checked /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/contrib/admin/templates/ and unfortunately nor my directory nor my files were there.
I tried Changing template 'DIRS', in settings.py to os.path.join(BASE_DIR, 'templates'), and rerunning the server,neither worked.
My templates setting:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]
Apps:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
I'm trying to install django-admin-tools in my existing Django installation. So far so good except for the fact that the backend looks fuzzy and afters some inspection it seems that utils.js is missing:
If I look into my static directory (after running python manage.py collectstatic) the file simply isn't there (it is in the installed Python package so I don't know if it's supposed to be there anyway but it might be a clue)
I think the problem might be related with my configuration, here some snippets of it:
MEDIA_URL = '/'
STATIC_ROOT = os.path.join('static')
STATIC_URL = '/static/'
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
INSTALLED_APPS = (
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'blog',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
'django.core.context_processors.static',
],
},
},
]
Django is 1.8.1
I'm wondering if anyone has some suggestions to fix this.
I've managed to fix this so for possible future readers:
The documentation (http://django-admin-tools.readthedocs.org/en/latest/configuration.html) states that django-admin-tools is modular. I thought that configuring installed apps with the above configuration was correct, it wasn't.
Although all the installed components seemed to work. Collectstatic probably couldn't find all the required files (files that belong to the base 'admin-tools' app).
The solution was to add 'admin-tools' to installed_apps so it looks like:
INSTALLED_APPS = (
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
(...)
)
I'm a Django beginner and I encounter an issue with django context_processors.
I want use a queryset in all my template for generate a menu.
But I get this error when I try to reach this page http://mysite/catalog which calls my cardabelle/catalog/views.py :
ImportError at /catalog/
No module named 'cardabelle.catalog'
Here "cardaballe" is my project name and "catalog" my application name.
Here is some interesting part (i guess) from my cardabelle/cardabelle/settings.py :
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'debug_toolbar',
'catalog',
'autoslug',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'template')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'cardabelle.catalog.context_processors.categories',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'cardabelle.wsgi.application'
and here is my custom context in cardabelle/catalog/views.py :
def categories(request):
return Category.objects.value()
Somebody knows why django doesn't find my new custom context ?
Thanks in advance for your help !
I guess you have the file context_processors.py in the directory catalog, which is on the same level as the directory cardabelle?
/catalog
__init__.py
context_processors.py
...
/cardabelle
__init__.py
settings.py
...
If yes, the context_processor setting should read
TEMPLATES = [
{
# ...
'OPTIONS': {
'context_processors': [
# ...
'catalog.context_processors.categories',
# ...
],
},
},
]
Also the context_processor should return a dict. Your current code reads Category.objects.value(). This is probably a typo while pasting it to SO? Just in case, make sure it reads Category.objects.values(), which returns a list of dicts.
def categories(request):
return {'menu_categories': Category.objects.values()}
It will then be available as {{ menu_categories }} in your templates.