Ubuntu 14.04
Python 3.4.0
Django 1.7
I just followed the 4 step directions to set up flatpages, but when I ran python3 manage.py migrate, none of the DB tables for the flatpages were created. All the other tables were created, just not the ones needed to flatpages. I'm pretty puzzled by this, 'cause this isn't complicated. I added the right stuff into my settings.py --
SITE_ID = 1 # added for flatpages
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites', # added
'django.contrib.flatpages.urls', # added for flatpages
)
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.contrib.flatpages.middleware.FlatpageFallbackMiddleware', #added
)
...and into my urls.py (though I don't think this could affect DB table creation) --
from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView
from django.contrib import admin
urlpatterns = patterns('',
# Examples:
url(r'^$', 'pets.views.home', name='home'),
url(r'^pages/', include('django.contrib.flatpages.urls')),
url(r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt',
content_type='text/plain')),
url(r'^admin/', include(admin.site.urls)),
)
...am I having a brain fart or something? I don't see why this won't work, but it's just not creating the DB tables needed for flatpages. This isn't my 1st time creating something with Django, but it is my 1st time trying out flatpages.
Yes, probably a brain fart: you've added the urls module to INSTALLED_APPS, rather than the app itself.
'django.contrib.flatpages', # added for flatpages
Related
i'm trying to use sub-domain for api in my project and using django-hosts for that.but after implementing it as documented there is Page not found (404) error is coming when I'm accessing any URL of my app 'api'
project/hosts.py
from django_hosts import patterns, host
from django.conf import settings
host_patterns = patterns('',
host(r'www', settings.ROOT_URLCONF, name='www'),
host(r'api', 'apps.api.urls', name='api'),
)
project/settings.py
def ip_addresses():
ip_list = []
for interface in netifaces.interfaces():
addrs = netifaces.ifaddresses(interface)
for x in (netifaces.AF_INET, netifaces.AF_INET6):
if x in addrs:
ip_list.append(addrs[x][0]['addr'])
return ip_list
ALLOWED_HOSTS = ip_addresses()
ALLOWED_HOSTS.append('.localdemo.in')
ALLOWED_HOSTS.append('.api.localdemo.in')
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'apps.core',
'apps.api',
# Third party
'django_hosts',
]
MIDDLEWARE = [
'django_hosts.middleware.HostsRequestMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'drf_api_logger.middleware.api_logger_middleware.APILoggerMiddleware',
'django_hosts.middleware.HostsResponseMiddleware',
]
ROOT_URLCONF = 'project.urls'
ROOT_HOSTCONF = 'project.hosts'
DEFAULT_HOST = 'www'
project/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('apps.core.urls')),
]
handler404 = "apps.core.views.customerrors.custom_handler404"
handler403 = "apps.core.views.customerrors.custom_handler403"
apps/api/urls.py
from django.urls import path, include, re_path
from django.conf.urls import url
from .views import statisticsview
urlpatterns = [
path('v1/statistics', statisticsview.StatisticsListView.as_view(), name='statistics_list'),
re_path(r'^statistics/$', statisticsview.StatisticsListView.as_view(), name='statistics_list'),
re_path(r'statistics/', statisticsview.StatisticsListView.as_view(), name='statistics_list'),
hosts file inside
windows/system32/drivers/etc/hosts
127.0.0.1 localdemo.in
127.0.0.1 api.localdemo.in
now when I'm accessing localdemo.in:8000 its working fine but I'm to unable to access api.localdemo.in:8000/v1/statistics/
there is page not found error and i'dont know why tried every urlpatter written in api/urls.py
only URL is working in which URL path is empty like this one at api.localdemo.in:8000 but others are not working(page not found error at api.localdemo.in:8000/v1/statistics/)
re_path('', statisticsview.StatisticsListView.as_view(), name='statistics_list'),
I am setting up django with multitenant architecture. I went through the https://django-tenant-schemas.readthedocs.io/en/latest/install.html
instruction and get to the point that have inital startup screen.
What I want to achieve is to enable admin module for each tenant.
my in settings.py I have following:
#Application definition
SHARED_APPS = (
'tenant_schemas', # mandatory, should always be before any django app
'customers', # you must list the app where your tenant model resides in
'django.contrib.contenttypes',
# everything below here is optional
)
TENANT_APPS = (
'django.contrib.contenttypes',
# your tenant-specific apps
# 'myapp.hotels',
# 'myapp.houses',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
)
INSTALLED_APPS = [
'tenant_schemas',
'customers',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
]
TENANT_MODEL = "customers.Client"
MIDDLEWARE = [
'tenant_schemas.middleware.TenantMiddleware',
'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 = 'sitemanager.urls'
PUBLIC_SCHEMA_URLCONF = 'sitemanager.urls_public'
when trying to open http://localhost:8000/admin getting error:
DoesNotExist at /admin/login/
Site matching query does not exist.
Request Method: GET
Request URL: http://localhost:8000/admin/login/?next=/admin/
Django Version: 2.1.2
Exception Type: DoesNotExist
Exception Value:
Site matching query does not exist.
my urls.py:
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
What am I missing in configuration?
Adding PUBLIC_SCHEMA_NAME = 'public' sort the problem.
I think django.contrib.sites should be in SHARED_APPS.
Kudos for using django-tenant-schema +1
Then to create a superuser :./manage.py tenant_command createsuperuser
Might be handy.
I'm using django-cookiecutter to bootstrap my project which will include api paths. Following the steps in Two Scoops of Django 1.11 to configure my urls to follow a similar pattern to this:
api/foo_app/ # GET, POST
api/foo_app/:uuid/ # GET, PUT, DELETE
api/bar_app/ # GET, POST
api/bar_app/:uuid/ # GET, PUT, DELETE
When I try to setup my project like this I'm getting the following error:
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'my_project.core.api_urls' from /Users/username/Development/my_project/my_project/core/api_urls.py'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
My current setup:
my_project.config.settings.base.py
ROOT_URLCONF = 'config.urls'
DJANGO_APPS = [
# Default Django apps:
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Useful template tags:
# 'django.contrib.humanize',
# Admin
'django.contrib.admin',
]
THIRD_PARTY_APPS = [
'crispy_forms', # Form layouts
'allauth', # registration
'allauth.account', # registration
'allauth.socialaccount', # registration
'rest_framework',
]
# Apps specific for this project go here.
LOCAL_APPS = [
# custom users app
'my_project.users.apps.UsersConfig',
'my_project.core.apps.CoreConfig',
]
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
my_project.config.urls.py
from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic import TemplateView
from django.views import defaults as default_views
urlpatterns = [
url(r'^users/', include('my_project.users.urls', namespace='users')),
url(r'^api/', include('my_project.core.api_urls', namespace='api')),
]
my_project.core.api_urls.urls
from django.conf.urls import url
from django.views.defaults import page_not_found
urlpattenrs = [
url(
regex=r'^users/$',
view=page_not_found,
),
]
The core app does not contain any models right now. It's just where I'm organizing all the URLs
"urlpattenrs" should be "urlpatterns" (in my_project.core.api_urls.urls) ;)
I'm using Django (1.7.3) with zinnia blog (0.15.1) and I'm having an issue for rendering the 'image for illustration' that you can add for a blog entry.
I have the following urls.py files:
My top-dir url conf
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^ecv/', include('extended_cv.urls',namespace="ecv")),
url(r'^weblog/', include('zinnia.urls', namespace='zinnia')),
url(r'^comments/', include('django_comments.urls')),
)
The settins.py file:
# -*- coding: utf-8 -*-
** Snip**
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
# For using django.contrib.sites
SITE_ID = 2
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pro',
'extended_cv',
'zinnia', # Added for zinnia blog usage
'django.contrib.sites',# Added for zinnia blog usage
'django_comments',# Added for zinnia blog usage
'mptt',# Added for zinnia blog usage
'tagging',# Added for zinnia blog usage
)
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',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.i18n',
'django.core.context_processors.request',
'zinnia.context_processors.version',
)
** Snip**
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
When I create an entry for zinnia using admin UI, and when I add an image, no error appear, and the new entry is saved to database with no warning. The image then appear in the server tree file at the adress TopDir/upload/zinnia/date/of/publication/index_IKd2N0d.jpeg
But, when I read the new entry from the weblog app, I correctly see the new entry, but not the image. Moreover, the server output the following error:
GET /weblog/2015/01/18/1st-entry/uploads/zinnia/2015/01/18/index_IKd2N0d.jpeg HTTP/1.1" 404 8922
I guess the issue is kind of complicated to debug, then if you need more information, I'll be happy to give you more.
Thank you.
As explain by Daniel Roseman in the comments, the answer consists into defining the variables MEDIA_URL and MEDIA_ROOT, and to rewrite the top urls.py file as explained in https://docs.djangoproject.com/en/1.7/howto/static-files/#serving-files-uploaded-by-a-user-during-development:
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^ecv/', include('extended_cv.urls',namespace="ecv")),
url(r'^weblog/', include('zinnia.urls', namespace='zinnia')),
url(r'^comments/', include('django_comments.urls')),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
And the work is done.
I can't figure out why Django is not loading the admin page. It seems like it isn't even reading the urls.py file that I am editing - because even if I comment out the 'urlpatterns' statement, it still loads the local hello page fine once I run the server.
This is the error message:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/admin
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^hello/$
^time/$
^time/plus/(\d{1,2})/$
The current URL, admin, didn't match any of these.
This is my urlpatterns code:
from django.conf.urls import patterns, include, url
from mysite.views import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
('^hello/$', hello, ),
('^time/$', current_datetime, ),
(r'^time/plus/(\d{1,2})/$', hours_ahead, ),
# Examples:
# url(r'^$', 'mysite.views.home', name='home'),
# url(r'^mysite/', include('mysite.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls))
)
And this is a snippet os my settings.py file:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
# 'django.contrib.messages.middleware.MessageMiddleware'
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'mysite.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'mysite.wsgi.application'
TEMPLATE_DIRS = (
'/Users/pavelfage/Desktop/Coding/mysite/Templates',
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
# 'django.contrib.messages',
# 'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'mysite.books'
)
Any help much appreciated!
I faced same problem. Uncommenting from django.contrib import admin in urls.py solved the problem.
I had the same problem. You may try this:
In your urls.py replace the call include(admin.site.urls) by this: admin.site.urls
In your setting.py if don't have any TEMPLATE_CONTEXT_PROCESSORS property (that was my situation) add this:
TEMPLATE_CONTEXT_PROCESSORS = ("django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.core.context_processors.static", "django.core.context_processors.tz", "django.contrib.messages.context_processors.messages")
It seams to be roughly the default property in a normal django 1.4 configuration. Here are the docs talking about it: djangoproject-doc1 djangoproject-doc2
You may also have to uncomment the strings:
# 'django.contrib.messages',
# 'django.contrib.staticfiles',
in your INSTALLED_APPS property of the settings.py but i'm not sure about it.
Sorry about not explaining much better the reasons of those changes but I'm a django-beginner to. I just found your question corresponding to my problem and then a possible awnser.
I hope it may help you.
EDIT: as seen in a comment you may try to remove the url(...) instruction on the line concerning the url of the admin site
ben