Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error "No Newsletter matches the given query." depending on site setting of newsletter #354

Open
TommyK82 opened this issue Dec 6, 2020 · 10 comments

Comments

@TommyK82
Copy link

TommyK82 commented Dec 6, 2020

HI,

I found your app, which is really amazing.

Anyway I am reading the docs for 2 days and cant find an answer.

I installed everything like in the docs (I am using django 3.1.3 ; django-newsletter 0.9.1; python 3.8.5)

Newsletter sign up works when I set "example.com" site for the newsletter "test3":
[06/Dec/2020 19:32:22] "GET / HTTP/1.1" 200 11928
[06/Dec/2020 19:32:28] "POST /newsletter/test3/subscribe/ HTTP/1.1" 302 0
[06/Dec/2020 19:32:28] "GET /newsletter/test3/subscribe/email-sent/ HTTP/1.1" 200 469

But If I set the localhost "http://127.0.0.1:8000/" as site for the newsletter "test3" then nothing works
Not Found: /newsletter/test3/subscribe/
[06/Dec/2020 19:38:45] "POST /newsletter/test3/subscribe/ HTTP/1.1" 404 1787

Error-page:
Page not found (404)
Request Method: POST
Request URL: http://127.0.0.1:8000/newsletter/test3/subscribe/
Raised by: newsletter.views.SubscribeRequestView

No Newsletter matches the given query.

Any clue? Thanks a lot

Below again the setting as picture, newsletter sign up working or not depending on "site" setting

setting

P.S.: another "issue" I have is copying the ‘stub’-templates to the project_dir does not change a thing, there are still the templates from the package linked

@TommyK82
Copy link
Author

Here is an update: I have the same behavior on the server, with having the website name setted as "site", any hint would be really great ..

Error:
Page not found (404)
Request Method: POST
Request URL: http://mywebsite.com/newsletter/test3/subscribe/
Raised by: newsletter.views.SubscribeRequestView

No Newsletter matches the given query.

@frennkie
Copy link
Collaborator

Are you accessing newsletter/test3/subscribe/ as an authorized users (e.g. admin)? Or is this a separate browser session?

P.S.: another "issue" I have is copying the ‘stub’-templates to the project_dir does not change a thing, there are still the templates from the package linked

"Hiding" issue in a P.S. is not not a good idea as it might be overlooked or lead to confusion in the discussion. If this is a problem for you and you can't find a solution then please open another issue.

@frennkie
Copy link
Collaborator

The 127.0.0.1:8000 setting should work.

Are you doing anything special otherwise? Is this a "clean" project or are you trying to add it to an existing site (where other apps are active that might have an impact)?

@TommyK82
Copy link
Author

TommyK82 commented Dec 13, 2020

@freenkie thanks for the reply, you are absolutly right about the thing in the P.S. ... anyway this is no issue here

I included the form described here: https://django-newsletter.readthedocs.io/en/latest/usage.html#embed-a-sign-up-form-within-any-page

And when a page-vistor uses this form for a sign up (using double opt in) then the error above appears. The errors appears regardless if I am logged in as admin or not.

I just tried again with 127.0.0.1:8000 as "site" for the newsletter "test3", still not working, and still working when I choose example.com as "site" for the newsletter "test3" (setting in the admin interface)

Any hints how I can find out the issue are appreciated.

Yes this is a clean project

@frennkie
Copy link
Collaborator

frennkie commented Dec 13, 2020

The "Site" field is a multi select list. You need to select all sites for which you want the newsletter to be active.

If only example.com is selected, then only example.com works.

If you want others (e.g. localhost) to work the you need to select them too and save.

@TommyK82
Copy link
Author

TommyK82 commented Dec 13, 2020

Yes I know, I just tried to say that the newsletter signup works perfectly when I choose "example.com" (really the value example.com like in the pre-settings)

But it is not working on server (having the realswebsite as "site" or "127.0.0.1:8000" when developing on localhost.

--> Means the newsletter sign up is working, the error is maybe caused by some missing "wildcard" when I choose 127.0.0.1:8000 instead of "example.com".

When email sign up is working (using example.com as site) then it is working and I am directed to http://127.0.0.1:8000/newsletter/test3/subscribe/email-sent/ (which works)

When email sign up is not working (using 127.0.0.1:8000 as site) then the error apears http://127.0.0.1:8000/newsletter/test3/subscribe/ is not available.

So I assume there is some setting wrong to allow some kind of wildcard..

@frennkie
Copy link
Collaborator

What do you mean by wildcard?

Can you again post the exact settings and URL of the case that you are trying and that fails?

@TommyK82
Copy link
Author

TommyK82 commented Dec 13, 2020

Really just a minum example check settings below ... many thanks for helping ..

Also I dont want to waste your time, a minimum working example with the sign up form would maybe help me enough ...

To get the minimum example working I also needed to add SITE_ID = 1 to the settings, I wonder if this causes these errors. But running the Server is not possible without that ( but no hint in the docs about that)...

Here is settings.py:

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'some_key'

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

ALLOWED_HOSTS = ['127.0.0.1:8000']

# Application definition

INSTALLED_APPS = [
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.auth',
    'django.contrib.sites',
    'django.contrib.admin',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'sorl.thumbnail',
    'newsletter',
    'website',
]

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 = 'mysite.urls'

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',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

STATIC_URL = '/static/'

SITE_ID = 1


@woodz-
Copy link

woodz- commented Feb 3, 2021

I suggest to take #357 into a preconfigured venv and test it for a while. I am pretty sure the pitfall is the SITE_ID in settings.py which breaks multiple configured sites via the admin panel. It causes pain for a long time.
The author @zelenij stated it does its job on a prod domain.

@AliMejbar
Copy link

AliMejbar commented Feb 28, 2021

Up I've just encountered this problem , it was working fine with SQLite but when i migrated to PostgreSQL i started having this issue. I don't find any explanation of how it happens.

update : fixed it by manually changing the id of the site to 1 (it was 3) using pgAdmin4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants