Success message not displayed in Django ClassBasedView - python

I am trying to display success message after saving form. I am using message framework for this
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE_CLASSES = [
'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',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_PATH],
'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',
],
},
},
]
views.py
class VolunteerCreateView(SuccessMessageMixin, CreateView):
model = Volunteer
form_class = VolunteerForm
template_name = 'volunteer.html'
success_message = 'Thank you!'
success_url = reverse_lazy('volunteer')
volunteer.html
{% if messages %}
<div class="alert center block" role="alert">
<ul class="messages">
{% for message in messages %}
<li class="text-center"{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
</div>
{% endif %}.....
But the message is not displayed. I can see the message json on request header in redirected url but is not displayed.
Part of request header
Cookie:olfsk=olfsk1757071755791586; hblid=HecPjm2lDQ2xTzgn3m39N0J00JEB6o1A; sessionid=z8zh4t13mw655mf3yn1vfnow8y58zxt9; csrftoken=GZxsdPZmBsefPU0nv7ZEfEaxsnPCMjIehpiFihY3GtTrhFnuFc5c3NXplD35Qslw; ext_name=jaehkpjddfdgiiefcnhahapilbejohhj;
messages="ab8f5c6976dd0939d4f1b867ca564577ba9cc0d7$[[\"__json_message\"\0540\05425\054\"Thank you!\"]]"
What could be the reason that message is not displayed. Is there anything I am missing.

Related

How to properly configure media files editing and viewing in templates

I have create a small project , where i am stuck at one point
Issue : not able to get images dynamically and display in template
i.image.url -> at this line in html images are not coming from folder media
when i runserver the media folder is not getting created and images are not copied from pics to media folder
seetings.py
BASE_DIR = Path(__file__).resolve().parent.parent
DEBUG = True
ALLOWED_HOSTS = []
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR,'web_components')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL='/media/pics/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'LEARN_FROM_TELUSKO',
]
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 = 'PROJECT.urls'
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',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.media',
],
},
},
]
urls.py
urlpatterns = [
path('', include('LEARN_FROM_TELUSKO.urls')),
path('admin/', admin.site.urls)
]
urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
models.py
class courses(models.Model):
name = models.CharField(max_length=100)
price = models.IntegerField()
image = models.ImageField(upload_to='pics', height_field=None, width_field=None, max_length=None)
views.py
def index(request):
dest = courses.objects.all()
return render(request,'index.html',{'getdetails':dest})
template
{% for i in getdetails %}
<div class="col-xl-3 col-lg-3 col-md-6 col-sm-12">
<div class="product-box">
<i>
<img src="{{ i.image.url }}"/>
</i>
<h3>{{ i.name }} </h3>
<span>{{ i.price }}</span>
</div>
</div>
{% endfor %}
Project structure:
I uploaded files to 127.0.0.1/8000/admin:
Here they are mentioned in the db

Q: django-simple-menu - menu doesn't load

my django-simple-menu doesn't work. My code very closely resembles the example from the doku https://django-simple-menu.readthedocs.io/en/latest/usage.html#usage-example.
The page loads without the menu links and I get no errors messages. Would be grateful for any ideas on how to solve this.
Django: 3.0.1
Python: 3.7.5
nav.html
<nav class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
{% for item in menu %}
<li class="nav-item active">
<a class="nav-link" href="{{ item.url }}">{{ item.title }} <span class="sr-only">(current)</span></a>
</li>
{% endfor %}
</ul>
</div>
</nav>
base.html
{% load menu %}
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
...
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static '/css/base.css' %}">
</head>
<body>
{% if user.is_authenticated %}
<div class="d-flex bg-dark header " >
<div class="p-2 flex-grow-1 bg-dark "> </div>
<div class="p-2 bg-dark ">User: {{ user.username }} </div>
<div class="p-2 bg-dark">Logout</div>
</div>
{% generate_menu %}
{% with menu=menus.main %}{% include 'nav.html' %}{% endwith %}
{% else %}
....
{% endif %}
<main>
...
</main>
</body>
</html>
setttings.py
"""
Django settings for nsap project.
Generated by 'django-admin startproject' using Django 3.0.1.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '+hari9jxke*m!4os*6gc!4ygk_hr5es-qdx)x=qza7)7m&x&%='
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'userManagement.apps.UsermanagementConfig',
'doppik.apps.DoppikConfig',
'base.apps.BaseConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'menu',
]
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 = 'urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
BASE_DIR + '/nsap/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 = 'wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
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',
},
]
# USER Model
#AUTH_USER_MODEL = 'core.User'
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Europe/Berlin'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
PROJECT_NAME = 'nsap'
STATIC_ROOT = os.path.join(BASE_DIR, PROJECT_NAME, 'staticfiles')
STATIC_URL = os.path.join(BASE_DIR, PROJECT_NAME, 'static/')
#MEDIA_URL = '/media/'
#MEDIA_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..','..', 'media'))
# Loging
LOGIN_REDIRECT_URL = '/'
menus.py
from menu import Menu, MenuItem
from django.urls import reverse
Menu.add_item("main", MenuItem("Booking",
reverse("doppik.views.booking"),
weight=10,
icon="tools"))
Menu.add_item("main", MenuItem("ShowAccount",
reverse("doppik.views.show_accounts"),
weight=10,
icon="tools"))
Menu.add_item("main", MenuItem("Login",
reverse('django.contrib.auth.views.login'),
check=lambda request: not request.user.is_authenticated()))
Menu.add_item("main", MenuItem("Logout",
reverse('django.contrib.auth.views.logout'),
check=lambda request: request.user.is_authenticated()))
Edit:
I think the problem is that menus.py is not running and no MenuItems are added to Menu.
I have added the command print("foo") to the menus.py file. The output does not display in the terminal.
Are you running the pip installed build, or have you tried this fork that has Django 2.2 support? https://github.com/skunkie/django-simple-menu/ I imagine the original build may have some compatibility issues.

How to fix issues with Django registration template importation/referencing

I have recently started a blog using django from Corey Schaeffer's tutorial. I am stuck at part 6: User Registration, the feedback says template does not exist at users/register.html at line 19.
I have attempted to send the directory in settings to the absolute location of my templates, but it keeps responding with the same feedback.
I must be incorrectly referencing in my register.html or settings. Or even worse, a clerical/technical error!
My settings file
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = 'lzjtwkmz)f5nmj+#^vmiu^2rk+!24f1if72aq81+ny=wiiwn+g'
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [
'blog.apps.BlogConfig',
'users.apps.UsersConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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 = 'django_project2.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['C:/Users/sabay/django_project2/blog/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 = 'django_project2.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
my register.html file
{% extends "blog/base.html" %}
{% block content %}
<div class="content-section">
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Join Today</legend>
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Sign Up</button>
</div>
</form>
<div class="border-top pt-3">
<small class="text-muted">
Already Have An Account? <a class="ml-2" href="#">Sign In</a>
</small>
</div>
</div>
{% endblock content %}
my urls.py
from django.contrib import admin
from django.urls import path, include
from users import views as user_views
urlpatterns = [
path('admin/', admin.site.urls),
path('register/', user_views.register, name='register'),
path('', include('blog.urls')),
]
I expect the output to result in webpage of the register page however the actual result leads to me a 'TemplateDoesNotExist at /register/'.
Any help would be appreciated, and sorry if the code text is horrendous to look at, this is my first time using stackover flow.
Try without the / in front of register, 'register/' instead of '/register/'

Django Session variables not updating properly

I am trying to figure out how sessions work. Basically I am trying to make a restaurant menu and store ordered food into session for further use. However, I ran into a problem and I cant figure out what might be the problem.
The problem is that if I submit the form 1st time. The success view shows the correct data.
I click Submit (pridat) and it works correctly
The output is:
('2', 1)
Where number 2 is food ID and 1 is the quantity.
Then I go back to the menu and I want to update the quantity to lets say 3
I change quantity (mnozstvo) to 3 and submit
But the output is still:
('2', 1)
The weirdest thing that has me confused is the fact that for example different food, even though it should be generated the same way works and updates just fine.
If I want to "order" multiple things it works fine with some and sometime one or multiple just refuse to update properly. As I am writing this 3 out of 4 works just fine.
('3', 5)('4', 8)('1', 15)('2', 1)
I can change 3-5, 4-8 and 1-15 but the 2-1 just never ever changes.
If I restart the built in django server sometimes different pair does not update properly. This time it is 2-1 but I also had an issue that 3-5 would not update.
So I would be really happy if someone could tell me what am I doing wrong? I know I am not letting django generate form but I rather do it manually in html, but that should not be the problem, should it?
menu.html with form separated for better visibility
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'restaurant/style.css' %}" />
{% if all_food_list %}
<center>
<ul>
<li>Home</li>
<li>Menu</li>
<li style="float:right"><a class="active" href="#about">Objednavka</a></li>
</ul>
<div class="clearfix">
{% for food in all_food_list %}
<div class="div1">
<center>
<img src="{{ MEDIA_URL }}{{ food.picture.url }}" alt="{{ food.name }}">
<h2> {{ food.name}} </h2>
<p>Cena: {{ food.price }}czk</p>
<p>Hmotnost: {{ food.weight}}g</p>
<p>Zlozenie: {{ food.ingredients}}</p>
<form action="/get_food/" method="post">
{% csrf_token %}
Mnozstvo: <input id="test" type="number" name="quantity" min="0" max="30" step="1" value="1">
<input type="hidden" name="food_type" value="{{ food.id }}">
<input type="submit" value="Pridat">
</form>
</center>
</div>
{% endfor %}
TODO: Funkcny formular, view pre objednavku, nastavit limity div-ov.
</div>
</center>
{% else %}
<p>No food available.</p>
{% endif %}
My views.py
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.template import loader
from .models import Food
from .forms import FoodOrder
def index(request):
template = loader.get_template('restaurant/index.html')
request.session.flush()
return HttpResponse(template.render(request))
def menu (request):
all_food_list = Food.objects.order_by('name')
template = loader.get_template('restaurant/menu.html')
context = {
'all_food_list': all_food_list,
}
return HttpResponse(template.render(context, request))
def get_food(request):
if request.method == 'POST':
form = FoodOrder(request.POST)
if form.is_valid():
quantity = form.cleaned_data['quantity']
#Food_type is db food id
food_type = form.cleaned_data['food_type']
#add to the session
request.session[food_type] = quantity
return HttpResponseRedirect('/success/')
else:
return HttpResponseRedirect('/index/')
def success(request):
#just writes the content of session
obsah = request.session.items()
return HttpResponse(obsah)
# Create your views here.
forms.py
from django import forms
class FoodOrder(forms.Form):
quantity = forms.IntegerField()
food_type = forms.IntegerField()
settings.py
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'restaurant.apps.RestaurantConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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 = 'iis_project.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 = 'iis_project.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
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',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL = '/static/'
MEDIA_ROOT = 'D:\Škola\IIS\Projekt - Restaurace\media'
MEDIA_URL = '/media/'

Installed Django AllAuth, can't find login or signup

I just installed Django AllAuth to my project, but cant find default login or signup page.
1) I logged out from admin panel, but still didn't find it.
2) Added signup.html template, but nothing
Picture of error in localhost/accounts http://prntscr.com/9oyu00
Here's my code:
settings.py
# SECURITY WARNING: don't run with debug turned on in production!
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',
'profiles',
'contact',
'crispy_forms',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'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 = 'src.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 = 'src.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
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',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
if DEBUG:
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static", "static-only")
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static", "media")
STATICFILES_DIRS = (os.path.join(os.path.dirname(BASE_DIR), "static", "static"),
)
# Location of templates
CRISPY_TEMPLATE_PACK = 'bootstrap3'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
SITE_ID = 1
LOGIN_URL = '/accounts/login'
LOGIN_REDIRECT = '/'
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
ACCOUNT_CONFIRM_EMAIL_ON_GET = False
ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = LOGIN_URL
ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = None
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 3
ACCOUNT_EMAIL_REQUIRED = False
ACCOUNT_EMAIL_VERIFICATION = None
ACCOUNT_EMAIL_SUBJECT_PREFIX = "My subject: "
ACCOUNT_DEFAULT_HTTP_PROTOCOL = "http"
ACCOUNT_LOGOUT_ON_GET = False
ACCOUNT_LOGOUT_REDIRECT_URL = "/"
ACCOUNT_SIGNUP_FORM_CLASS = None
ACCOUNT_SIGNUP_PASSWORD_VERIFICATION = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USER_MODEL_USERNAME_FIELD = "username"
ACCOUNT_USER_MODEL_EMAIL_FIELD = "email"
ACCOUNT_USERNAME_MIN_LENGTH = 5
ACCOUNT_USERNAME_BLACKLIST = []
ACCOUNT_USERNAME_REQUIRED = True
ACCOUNT_PASSWORD_INPUT_RENDER_VALUE = False
ACCOUNT_PASSWORD_MIN_LENGTH = 6
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = True
urls.py
from django.conf.urls import url, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
from contact import views
urlpatterns = [
url(r'^$', 'profiles.views.home', name='home'),
url(r'^contact/$', views.contact, name='contact'),
url(r'^accounts/', include('allauth.urls')),
url(r'^admin/', admin.site.urls),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
signup.html
{% extends "account/base.html" %}
{% load crispy_forms_tags %}
{% load i18n %}
{% block head_title %}{% trans "Signup" %}{% endblock %}
{% block content %}
<h1>{% trans "Sign Up" %}</h1>
<p>{% blocktrans %}Already have an account? Then please sign in.{% endblocktrans %}</p>
<form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}">
{% csrf_token %}
{{ form|crispy }}
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}
<button class='btn btn-default' type="submit">{% trans "Sign Up" %} »</button>
</form>
{% endblock %}
I had the same problem. The source of it all was that I had already defined a base.html file without a 'block content' block. You need the following structure inside the body of your base.html file:
<body>
{% block body %}
{% block content %}
{% endblock content %}
{% endblock body %}
</body>
I used this source to find a suitable example, but it's not very helpful other than that. This other page was a bit better though.
Because you are requesting only the /accounts/ and if you see closely to your debugger (the screen) there is no URL for this (pattern ^accounts/ ^ ^$).
Your login & sing up page is located on /accounts/login/ and /accounts/singup/.
About editing default templates I am not able to help you with it (never used the AllAuth package) so hope someone skilled will help you.

Categories

Resources