Even though I am providing correct path it still giving me an error. in this project have made custom user model so I am not able to understand where i am going wrong.
And also added the required paths in settings. I tried the same code even by using include method in urls,py but still failed. where exactly i am making mistake?
setting.py:
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 = 'fw4g6x*9vn6sz)&v*$q-gppcwgd-%0&oo6_ydt(3t!#&uyz=xt'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
AUTH_USER_MODEL = 'account.Account'
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'account',
]
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, '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 = 'project.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',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/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/3.0/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
register.html:
{% block content %}
<h1>Register</h1>
<form action="register1" method="post">
{% csrf_token %}
{% for field in registeration_form %}
<p>
{{field.label_tag}}
{{field}}
{if field.help_text %}
<small style="color:grey;">{{field.help_text}}</small>
{% endif %}
{% fr error in field.errors %}
<p style="color:red;">{{error}}</p>
{% endfor %}
</p>
{% endfor %}
<button type="submit">Register</button>
</form>
{% endblock %}
urls.py
from django.contrib import admin
from django.urls import path
from account.views import (
register,
)
urlpatterns = [
path('admin/', admin.site.urls),
path('register/', register, name='register'),
]
views.py
from django.shortcuts import render, redirect
#from django.contrib.auth.models import User, auth
from django.contrib.auth import login, authenticate
from account.forms import RegistrationForm
def register(request):
context ={}
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
form.save()
aadhar = form.cleaned_data('aadhar')
raw_password = form.cleaned_data('password1')
account = authenticate(aadhar=aadhar,password=raw_password)
login(request, account)
return redirect('/')
else:
context['registration_form'] = form
else:
form = RegistrationForm()
context['registration_form'] = form
return render(request, 'account/register.html', context)
Error:
TemplateDoesNotExist at /register/
account/register.html
Request Method: GET
Request URL: http://127.0.0.1:8000/register/
Django Version: 3.0.4
Exception Type: TemplateDoesNotExist
Exception Value:
account/register.html
Exception Location: E:\phptodj\test1\venv\lib\site-packages\django\template\loader.py in get_template, line 19
Python Executable: E:\phptodj\test1\venv\Scripts\python.exe
Python Version: 3.7.4
Python Path:
['E:\\phptodj\\test1',
'E:\\phptodj\\test1',
'C:\\ProgramData\\Anaconda3\\python37.zip',
'C:\\ProgramData\\Anaconda3\\DLLs',
'C:\\ProgramData\\Anaconda3\\lib',
'C:\\ProgramData\\Anaconda3',
'E:\\phptodj\\test1\\venv',
'E:\\phptodj\\test1\\venv\\lib\\site-packages']
Server time: Tue, 17 Mar 2020 12:32:53 +0000
Your settings of the template in settings.py should be...
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
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',
],
},
},
]
And your folder structure should be...
project_name
|
app_1
|
app_2
|
account
|
templates
|
|__account
|
|__register.html
Related
I am struggling for 5 days, cant make it work. My code works perfectly fine on local server, but wont work when i upload application. It just won't accept any new data i just face some weird redirections to homepaage with the url of the page i made submit. The existing(imported) data can be manipulated and changed, just no way to submit new data.
{% extends "baza.html" %}
{% block content %}
{% load static %}
{% load crispy_forms_tags %}
<div class="container-login100" style="background-image: url('/static/images/pticica.jpg');">
<div class="wrap-login100">
<form method="POST" action="{% url 'Registracija' %}" enctype="multipart/form-data" class="login100-form">
{% csrf_token %}
<span class="login100-form-logo">
<i class="zmdi zmdi-landscape">
<img style="border-radius:100%;padding:5px;" src="/static/images/login.png">
</i>
</span>
<span class="login100-form-title p-b-34 p-t-27">Registruj se</span>
{{form|crispy}}
<button type="submit" class="btn btn-success">Registruj se</button>
</form>
</div>
</div>
{% endblock %}
my views
from django.shortcuts import render, redirect
from .forme import RegisterForm
def register(request):
if request.method == "POST":
form = RegisterForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect("login")
else:
form=RegisterForm()
return render(request,"register/register.html", {'form':form})
and global settings
from django.utils.translation import ugettext_lazy as _
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '{{ secret_key }}'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['ljubimac.me','www.ljubimac.me']
# Application definition
INSTALLED_APPS = ['Websajt',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'register',
'crispy_forms',
'allauth',
'allauth.account' ,
'allauth.socialaccount' ,
'allauth.socialaccount.providers.github',
'Users',
]
SITE_ID = 1
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'Sajt.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 = 'Sajt.wsgi.application'
# Database
# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'deniggsm_ljubimac',
'HOST': 'localhost',
'USER': 'deniggsm_Andrija_Culafic',
'PASSWORD':'protokol123',
'PORT': '3306',
}
}
# Password validation
# https://docs.djangoproject.com/en/{{ docs_version }}/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/{{ docs_version }}/topics/i18n/
LANGUAGE_CODE = 'sr'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LOCALE_PATHS=[
os.path.join(BASE_DIR,'locale')
]
STATIC_URL=('/static/')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
#email
EMAIL_HOST='smtp.gmail.com'
EMAIL_PORT='465'
EMAIL_HOST_USER="selastan#gmail.com"
EMAIL_HOST_PASSWORD="extractor361"
EMAIL_USE_SSL="True"
DEFAULT_FROM_EMAIL = 'noreply<no_reply#domain.com>'
SITE_ID = 1
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
LOGIN_REDIRECT_URL='/'
LOGOUT_REDIRECT_URL='/login'
ADMIN_MEDIA_PREFIX = '/media/'
AUTH_USER_MODEL = 'Users.NewUser'
url patterns
from django.urls import include,path
from . import views
from django.contrib import admin
from django.conf.urls.static import static
from register.views import register
from django.conf import settings
urlpatterns = [
path('',views.Naslovna,name='Naslovna'),
path('postavi-oglas/',views.Oglasss,name='Oglasss'),
path('svi-oglasi/<slug:slug>/',views.Pojedinacni_Oglas,name='Pojedinacni'),
path('svi-oglasi',views.Sviii,name='Svi_Oglasi'),
path('svi-oglasi/sortiranje',views.Sortiranje,name='Sortiranje'),
path('registracija/',register,name="Registracija"),
path('admin/',admin.site.urls),
path('moj-profil',views.MojProfil,name='Profil'),
path('promijeni-lozinku/',views.PromijeniSifru,name="Lozinka"),
path('kategorije/',views.Kategorije,name="Kategorijaaa"),
path('Psi/',views.Psi,name="Psiii"),
path('Mačke/',views.Mačke,name="Mačkeee"),
path('Ptice/',views.Ptice,name="Pticeee"),
path('Reptili/',views.Reptili,name="Reptiliii"),
path('Ribice/',views.Ribice,name="Ribiceee"),
path('Glodari/',views.Glodari,name="Glodariii"),
]
url.py in root
from django.urls import include,path
from django.contrib import admin
from django.conf.urls import include
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls.static import static
urlpatterns = [
path('',include('Websajt.urls')),
path('',include('django.contrib.auth.urls')),]
urlpatterns+=static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
edited register view
from django.shortcuts import render, redirect
from .forme import RegisterForm
def register(request):
if request.method == "POST":
form = RegisterForm(request.POST, request.FILES)
if form.is_valid():
form.save()
print(form.errors)
return redirect("login")
else:
form=RegisterForm()
return render(request,"register/register.html", {'form':form})
I met a problem.
When I choose a photo as a profile_pic on the registration page,
it saves any information without a photo.
But I can't find out why it didn't work.
There is nothing in the Profile pic after submitting.
setting.py
"""
Django settings for learning_templates project.
Generated by 'django-admin startproject' using Django 3.1.7.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATE_DIR=os.path.join(BASE_DIR,'templates')
STATIC_DIR=os.path.join(BASE_DIR,'static')
MEDIA_DIR=os.path.join(BASE_DIR,'media')
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'pgmh_#pcqd(3sf(a3oj#^vyv4l-#p6g=n-=^!z)0d#!k)!_ear'
# 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',
'basic_app',
]
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 = 'learning_templates.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR,],
'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 = 'learning_templates.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
PASSWORD_HASHERS=[
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
'django.contrib.auth.hashers.Argon2PasswordHasher',
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
]
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'OPTIONS':{'min_length':9}
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/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/3.1/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS=[STATIC_DIR,]
#MEDIA
MEDIA_ROOT=MEDIA_DIR
MEDIA_URL='/media/'
LOGIN_URL='basic_app/user_login'
in views.py: register
def register(request):
registered= False
logging.error(request.method)
if request.method == 'POST':
user_form= UserForm(data=request.POST)
profile_form=UserProfileInfoForm(request.POST)
logging.error(user_form)
if user_form.is_valid() and profile_form.is_valid():
user=user_form.save()
user.set_password(user.password)
user.save()
profile=profile_form.save(commit=False)
profile.user=user
if 'profile_pics' in request.FILES:
profile.profile_pic=request.FILES['profile_pics']
profile.save()
registered=True
else:
print(user_form.errors,profile_form.errors)
else:
user_form=UserForm()
profile_form=UserProfileInfoForm()
return render(request,'basic_app/registeration.html',
{'user_form':user_form,
'profile_form':profile_form,
'registered':registered})
models.py
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class UserProfileInfo(models.Model):
user=models.OneToOneField(User,on_delete=models.CASCADE)
# additional
portfolio_site=models.URLField(blank=True)
profile_pic = models.ImageField(upload_to = 'profile_pics', blank = True)
def __str__(self):
return self.user.username
forms.py
class UserProfileInfoForm(forms.ModelForm):
class Meta():
model=UserProfileInfo
fields=('portfolio_site','profile_pic')
registeration.html
<!DOCTYPE html>
{% extends "basic_app/base.html" %}
{% load static %}
{% block body_block %}
{{registered }}
<div class=jumbotron>
<h1>Test Register</h1>
{% if registered %}
<h1>Thank you for Register</h1>
{% else %}
<h1>Register Here</h1>
<h3>
<h1>Fill out the form</h1>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ user_form.as_p}}
{{ profile_form.as_p }}
<input type="submit" name="" value="Register">
</form>
</h3>
{% endif %}
</div>
{% endblock %}
And I have made sure that the profile_pics folder has nothing.
I don't know where I am wrong or what I miss but anything without a photo has saved.
If anything misses, please tell me.
Thank you for your time.
First check if the uploaded images is in your media/profile_pics folder.
Since you are viewing the data uploaded using the django admin panel ,it does not shows the actual image it will show the image name.
Try to display the image in a template by passing the user content in the context section while sending the rendering the template.
I'm trying to send input text from index.html to my view function that is "result".
When I click the 'Generate Summary' button its shows csrf verification failed.Csrf token missing.Urgent help required.
views.py
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from .models import Input
from django.views.decorators.csrf import csrf_protect
def home(request):
input=Input.objects.all()
template=loader.get_template('home/index.html')
context={
'input':input,
}
return HttpResponse(template.render(context,request))
def result(request,input_text):
Input.input_text = request.POST('input_text')
return HttpResponse("<h1> text is"+Input.input_text)
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Title</title>
{% load staticfiles %}
<link rel='stylesheet'href="{% static 'css/bootstrap.min.css' %}" type='text/css'/>
</head>
<body background="/static/home/img/bg.jpg">
<center><h1> <font color="white" >Summarizeit.com !</h1></center>
<form name="myform" action="." method="post">{% csrf_token %}
<div class="form-group">
<center><label for="abc">Input Text</label>
<input type="text" name="input_text"class="form-group" id="abc"placeholder="Text input">
</div>
<br><br>
<center><button type="submit" class="btn btn-default"> Generate Summary !</button>
</form>
</body>
</html>
home/urls.py
from django.conf.urls import url, include
from . import views
urlpatterns = [
url(r'^$', views.home, name='home'),
]
finalproject/urls.py(Root Project)
from django.conf.urls import url,include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', include('home.urls'))
]
models.py
from django.db import models
class Input(models.Model):
input_text = models.CharField(max_length=250)
def __str__(self):
return self.input_text
Settings.py
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/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'y)m04wnmm%i_#uih%^j5&aqeozlp!gt#px&z!*uf=-%v98x#-i'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'home',
'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.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'finalproject.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 = 'finalproject.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(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/'
For some reason you're rendering your template the hard way, which bypasses all the automatic things that Django does for you: most importantly, running context processors that include the CSRF token.
Your view should be this:
def home(request):
input=Input.objects.all()
context={
'input':input,
}
return render(request, 'home/index.html', context)
Note also that your setting of Input.input_text in the result view makes no sense at all; you need to create an instance of Input, set its input_text, then save it.
I created an application and am using Django Redux Registration to handle authentication and creation of users, but I am not able to login unless it is a super user I created through the console. When I click "Register" again with the same username is says the name is already taken, but cannot login despite the password being correct. I can still login with superusers but nothing else.
Settings.py
"""
Django settings for yoloq project.
Generated by 'django-admin startproject' using Django 1.10.3.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/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/1.10/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'p(n=h+*3#9&c)qyyaa^fz3d0(w&hkzqr9p!k9y8#uld*0bz1is'
# 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.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'SearchGame',
'registration',
]
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 = 'yoloq.urls'
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',
],
},
},
]
WSGI_APPLICATION = 'yoloq.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 = 'EST'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
#DJANGO REGISTRATION REDUX SETTINGS
REGISTRATION_OPEN = True
ACCOUNT_ACTIVATION_DAYS = 7
REGISTRATION_AUTO_LOGIN = True
SITE_ID = 1
LOGIN_REDIRECT_URL = '/'
STATIC_URL = '/static/'
LOGIN_REDIRECT_URL = '/'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
Login.html
{% extends 'base.html' %}
{% block content %}
<h1>Login</h1>
<form method="post" action=".">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Log in" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
<p>Not a member? Register!</p>
{% endblock %}
Django Registration Redux Registers users but does not set them as active users. Hence when you try to login the Redux at the backend makes verification and allows login only if the active flag is set.
As the superuser is set with default active flag when created through createsuperuser command he is allowed to log in.
So in order to make the registered users to be able to login you need to set their active flag to true through admin panel or let them use the activation link if you are sending them for email verification.
mysite/settings.py
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 1.9.5.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/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/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '0hmrsl%ivudj7qe9+nz5l2w#s=op1urz_8*l5*)pv0+1d-j#^2'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'polls.apps.PollsConfig',
'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.auth.middleware.SessionAuthenticationMiddleware',
'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'
# 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/'
Everything looks fine. I'm not sure why it wont link up to my css. Looks like it can't find my static folder along with the stylesheet.
polls/templates/polls/index.html
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" />
{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li>{{ question.question_text }}</li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available</p>
{% endif %}
polls/static/polls/style.css
li a {
color: red;
}
From your settings.py that you posted you haven't set your STATIC_ROOT and from this I'm assuming you also haven't configured your urls.py for your static files either.
You can check out the documentation for how to set this up.