Saturday, February 28, 2015

[1.8] MultiHost with template dir per Host

Hi,

I had create a middleware, that is able to change the template directory per host on the fly.
But it stopped working since I upgraed to Django 1.8 and I tried to fix it.

My problem is:
If I visit domain1.tld, all works fine. Django loads the templates from the right directory. (/path/domain1.tld/templates/)
But if I visit now domain2.tld, Django tried to load the template from the domain1.tld directory /path/domain1.tld/templates/ and not from /path/domain2.tld/templates/.
The debug messages shows me, that the middleware overrides the template path successfully.

Maybe someone can help me to fix it.

Details:
Django version: 1.8b1
Python: 3.4

If you need some other information, just ask for it.

- settings.py
MIDDLEWARE_CLASSES = (
'core.middleware.MultiHostMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
...
)

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            ],
            'debug': True
        },
    },
]

ROOT_URLCONF = 'core.urls'

HOST_MIDDLEWARE_TEMPLATE_DIRS = {
   "domain1.tld": BASE_DIR + "/domain1.tld/templates/",
   "domain2.tld": BASE_DIR + "/domain2.tld/templates/",
}

HOST_MIDDLEWARE_URLCONF_MAP = {
   "domain1.tld": "domain1.urls",
   "domain2.tld": "domain2.urls",
}

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'core',
    'domain1',
    'domain2',
)

- middleware.py
from django.conf import settings
from django.utils.cache import patch_vary_headers


class MultiHostMiddleware:

    def get_settings(self, request):

        host = request.META["HTTP_HOST"]
        host_port = host.split(':')

        if len(host_port) == 2:
            host = host_port[0]

        if host in settings.HOST_MIDDLEWARE_URLCONF_MAP:

            urlconf = settings.HOST_MIDDLEWARE_URLCONF_MAP[host]
            template_dirs = settings.HOST_MIDDLEWARE_TEMPLATE_DIRS[host],

        else:
            urlconf = settings.ROOT_URLCONF
            template_dirs = None

        return urlconf, tuple(template_dirs)

    def process_request(self, request):

        urlconf, template_dirs = self.get_settings(request)

        request.urlconf = urlconf
        settings.TEMPLATES[0]['DIRS'] = template_dirs

    def process_response(self, request, response):

        if getattr(request, "urlconf", None):
            patch_vary_headers(response, ('Host',))

        return response



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/68d650a9-db37-46b9-8407-9eafd1404158%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Django Wysiwyg and images (Summernote or Froala)

Hi Dave,

I encounter the same problem. Did you find any solution?

I really don't know what is going wrong and the image does not appear.

Sakis

Τη Τετάρτη, 4 Φεβρουαρίου 2015 - 12:04:30 π.μ. UTC+2, ο χρήστης David Mutton έγραψε:
Hi,
I've been trying to integrate a WYSIWYG editor into my Django project. I first started with Summernote and I had no issue integrating the it into admin or a form. I followed the instructions on their github and everything works great except image uploading and inserting. The file is uploading (I can see it in the filesystem) but it does not show up in the editor or in the resulting html.

I thought it was just Summernote and so I switched to Froala but I'm getting the exact same behavior. Is there something I'm missing with image upload inside a wysiwyg?


Dave

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a0eb7cff-6423-4f86-b4ac-fea9604e6604%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Friday, February 27, 2015

Re: Django OperationalError

Hello James, will do but I am not at mine lap top atm, gona do it as soon as posible, tank you very much.

On Saturday, February 28, 2015, James Schneider <jrschneider83@gmail.com> wrote:
> Generally this happens when you don't apply the initial migration. Have you run 'python manage.py migrate' (assuming Django >= 1.7 since you mentioned making migrations) and if you have, what was the output? If you aren't sure, run it again as it shouldn't hurt anything.
>
> Check your database and make sure that the tables actually exist. If not, and there is no production data (assuming not based on the question), drop and recreate the DB to clear out any previously failed migration attempts and apply your migrations again using the command I specified. Capture the entire output of the command and paste it back to this list so that we can help more.
>
> -James
>
> On Feb 27, 2015 10:02 PM, "Petar Pilipovic" <iamrmot@gmail.com> wrote:
>>
>> Hello, I have manage to merge mine application to pythonanywhere.com. After I have done all the needed installing, uploading files, collecting static, making migrations to mine django application, I have experienced an OperationError saying:
>>
>> no such table: django_session
>> You can find the rest of mine question here on stackoverflow, Can someone help me over come this error, tank you.
>>  
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/01f5c13c-5b7e-40ea-b98b-e37640e477df%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/MOsaEEDNyQg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXfPuqKgQz89CVgaB07cf_Lwj%3DK-XcdtV9GK1EZ%3DQxMaQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK8niQsiLMaeLE%3D_8phdGhKqsYXuuL3nwStTJwXJQ%3D%2BrVuNYLQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Django OperationalError

Generally this happens when you don't apply the initial migration. Have you run 'python manage.py migrate' (assuming Django >= 1.7 since you mentioned making migrations) and if you have, what was the output? If you aren't sure, run it again as it shouldn't hurt anything.

Check your database and make sure that the tables actually exist. If not, and there is no production data (assuming not based on the question), drop and recreate the DB to clear out any previously failed migration attempts and apply your migrations again using the command I specified. Capture the entire output of the command and paste it back to this list so that we can help more.

-James

On Feb 27, 2015 10:02 PM, "Petar Pilipovic" <iamrmot@gmail.com> wrote:

Hello, I have manage to merge mine application to pythonanywhere.com. After I have done all the needed installing, uploading files, collecting static, making migrations to mine django application, I have experienced an OperationError saying:

no such table: django_session

You can find the rest of mine question here on stackoverflow, Can someone help me over come this error, tank you.
 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/01f5c13c-5b7e-40ea-b98b-e37640e477df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXfPuqKgQz89CVgaB07cf_Lwj%3DK-XcdtV9GK1EZ%3DQxMaQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Django OperationalError

Hello, I have manage to merge mine application to pythonanywhere.com. After I have done all the needed installing, uploading files, collecting static, making migrations to mine django application, I have experienced an OperationError saying:

no such table: django_session

You can find the rest of mine question here on stackoverflow, Can someone help me over come this error, tank you.
 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/01f5c13c-5b7e-40ea-b98b-e37640e477df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Migrations force me to have, forever, any name/reference I use in field validators=, choices=, whatever, valid forever (even if the requirements change).

Hello,

another solution may be to patch your models in the migration module or class, like:

import myapp.models

myapp.models.valid_identifier = something_acceptable()

Although it seems a bit ugly, I just tested it, and it works. This way valid_identifier will live during the migration only.

Best,
Gergely

On 27 Feb 2015 21:17, "Luis Masuelli" <luisfmasuelli@gmail.com> wrote:
Thanks :D Did not think about squashing migrations as solution for this problem! But it does the job.
OTOH the fact about historical models has nothing to do with my problem (since it is not related at all with instancing a model, but just about the definition and not getting a NameError).

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/15bb8a96-18a5-432c-afeb-7a3299ca7a4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACczBUJz9A%2ByKxTkP-prtfXihoSudM6V0HLD_mXUZTu2yQqjkg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Model field with default value and choices is always reported as changed, even if unchanged

Am 26.02.2015 um 19:06 schrieb Carsten Fuchs:
> The expected output is `False`,[...]

Just for future reference, this is continued here:
https://code.djangoproject.com/ticket/24428

Best regards,
Carsten

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/54F0DEB6.4010008%40cafu.de.
For more options, visit https://groups.google.com/d/optout.