Re: TemplateSyntaxError: 'subpackage.echo' is not a valid tag library

2015-11-12 Thread James Schneider
On Thu, Nov 12, 2015 at 5:10 AM, Jose Paul  wrote:

> I am just running DJango 1.8 test cases ,here is start of the error trace .
>
> =
> ERROR: test_load06 (template_tests.syntax_tests.test_load.LoadTagTests)
> --
> Traceback (most recent call last):
>   File
> "C:\Users\IBM_ADMIN\PythonWorkspace\DJangoTestCases\src\DJangoTestCases\tests\template_tests\utils.py",
> line 117, in inner
> func(self)
>   File "C:\Python27\lib\site-packages\django\test\utils.py", line 196, in
> inner
> return test_func(*args, **kwargs)
>   File
> "C:\Users\IBM_ADMIN\PythonWorkspace\DJangoTestCases\src\DJangoTestCases\tests\template_tests\utils.py",
> line 62, in inner
> func(self)
>   File
> "C:\Users\IBM_ADMIN\PythonWorkspace\DJangoTestCases\src\DJangoTestCases\tests\template_tests\syntax_tests\test_load.py",
> line 39, in test_load06
> output = self.engine.render_to_string('load06')
>   File "C:\Python27\lib\site-packages\django\template\engine.py", line
> 208, in render_to_string
>
>
I suspect one of your tests is rendering a template. Do you have a
reference to a template tag anywhere in your templates like {%
subpackage.echo %}? I'm guessing if you visit the page that has that
reference, it will also break in a similar manner. You probably need to add
a {% load tag_library %} or whatever your template tags are called in your
template before you call the template tag.

-James

-- 
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+unsubscr...@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%2BciW9D_7dyXPPY-G4WDAzQt0EKRcvUYJXqR5CKQ6%2Bu0-huw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Apache2, mod_wsgi and django setup

2015-11-12 Thread Gary Roach

Andrew;
I forgot all about the process tables. Thanks. Interesting though, 
systemctl and mod_wsgi both start a root instance and then fork off 3-4 
www-data instances. I assume that this is normal. The python manage.py 
runserver on the other hand doesn't even show up in the process table. I 
suspect it's using the internal development server. Nice to know.


James;
See below

On 11/12/2015 03:24 PM, James Schneider wrote:
On Thu, Nov 12, 2015 at 2:34 PM, Gary Roach > wrote:


Setup for Django development system

OS Debian Linux 8 (jessie) using systemd, not init.d
Python 3.4.2
Django 1.8.5
Apache2 2.4.10 Debian (mmm-worker)
mod_wsgi 4.3.0
Postgresql 9.4.5

Two virtual environments: archive (actual project) and mysite
(django tutorial). Setup done with python3 -m venv .
There seems to be some variation between this setup and the one
using virtualenv. Confusing.


Somewhat, yes, although both are effectively the same process. You end 
up with the same thing either way, though. The 'old' way of installing 
the virtualenv packages and then creating the virtualenv with external 
shell commands was integrated natively into Python 3 (ie your python3 
-m venv command), hence the confusion.
Thanks for the clarification. Between switching between Python 2 and 
Python 3, the differences between Debian and systemd vs the other 
versions and  everyone taking a different approach to the same problem, 
us novices get really confused.



pip3 install mod_wsgi in each environment
Run mod_wsgi-express with install-module and setup-server for each.


That's interesting, I've never heard of mod_wsgi-express. From a quick 
google though, it appears it should only be used for testing a 
mod_wsgi installation, not for production runs. Generally things work 
the other way around (Apache configured to use the mod_wsgi module as 
it is needed).
Which is exactly where I am at present. I'll fight the production stuff 
later.


In /etc/apache2/envvars the following environmental variables are set.
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data

In /etc/apache2/apache2.conf the following environmental variables
are used to set user and group.
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

But starting from within the project with mod_wsgi-express
start-server gives:

WARNING: When running as the 'root' user, it is required that the
options '--user' and '--group' be specified to mod_wsgi-express.

Starting with apachectl start or python manage.py runserver give
no errors. Both servers work.

Questions:
What user is apache running as if started with apachectl?


This tends to be distribution specific. Most often it will be www, or 
www-data. The serivce user account is generally specified by the 
service daemon management system configuration scripts for 
Apache/httpd (Systemd in this case).


  What user is apache running as if started with python
manage.py runserver?


It isn't. The runserver command is running its own bare-bones web 
server that is built into Python/Django (WEBrick IIRC, or at least it 
was previously). Only to be used for development, not for production.

Which I discovered to my surprise. See above.


  How do I assure that Apache is running as www-data?


Running ps -ef | grep -i '\(apache|http\)' should give you the user 
that the processes (Apache and all of its children) are running as in 
the first column.


  Do I need to start Apache with mod_wsgi-express --user
www-data --group www-data or is python manage.py runserver good
enough?


You should not be using either of those methods for a production 
installation of your project. Configure Apache directly to reference 
mod_wsgi.


https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/


Answers to these questions would be very very helpful

Gary R



Is there a specific reason that you installed a custom version of 
mod_wsgi? Most distributions provide a 2.7 and 3.X compatible version 
of mod_wsgi along with their Apache installations (or provide package 
installations for mod_wsgi for each respective Python version). 
High-end installations with node management and configuration control 
tend to use custom compiled versions since they can manage them 
effectively. The rest of us peasants are probably better off using the 
distribution packages until we figure out what we're doing (myself 
included).


Out of curiosity, I logged into one of my Debian 8 boxen and verified 
that this is the case:


$ apt-cache search mod-wsgi
libapache2-mod-wsgi - Python WSGI adapter module for Apache
libapache2-mod-wsgi-py3 - Python 3 WSGI adapter module for Apache

$ apt-cache showpkg libapache2-mod-wsgi-py3
Package: libapache2-mod-wsgi-py3
Versions:
4.3.0-1 

Re: Apache2, mod_wsgi and django setup

2015-11-12 Thread James Schneider
On Thu, Nov 12, 2015 at 2:34 PM, Gary Roach 
wrote:

> Setup for Django development system
>
> OS Debian Linux 8 (jessie) using systemd, not init.d
> Python 3.4.2
> Django 1.8.5
> Apache2 2.4.10 Debian (mmm-worker)
> mod_wsgi 4.3.0
> Postgresql 9.4.5
>
> Two virtual environments: archive (actual project) and mysite (django
> tutorial). Setup done with python3 -m venv . There seems to
> be some variation between this setup and the one using virtualenv.
> Confusing.
>

Somewhat, yes, although both are effectively the same process. You end up
with the same thing either way, though. The 'old' way of installing the
virtualenv packages and then creating the virtualenv with external shell
commands was integrated natively into Python 3 (ie your python3 -m venv
command), hence the confusion.


>
> pip3 install mod_wsgi in each environment
> Run mod_wsgi-express with install-module and setup-server for each.
>

That's interesting, I've never heard of mod_wsgi-express. From a quick
google though, it appears it should only be used for testing a mod_wsgi
installation, not for production runs. Generally things work the other way
around (Apache configured to use the mod_wsgi module as it is needed).


>
> In /etc/apache2/envvars the following environmental variables are set.
> export APACHE_RUN_USER=www-data
> export APACHE_RUN_GROUP=www-data
>
> In /etc/apache2/apache2.conf the following environmental variables are
> used to set user and group.
> User ${APACHE_RUN_USER}
> Group ${APACHE_RUN_GROUP}
>
> But starting from within the project with mod_wsgi-express start-server
> gives:
>
> WARNING: When running as the 'root' user, it is required that the options
> '--user' and '--group' be specified to mod_wsgi-express.
>
> Starting with apachectl start or python manage.py runserver give no
> errors. Both servers work.
>
> Questions:
> What user is apache running as if started with apachectl?
>

This tends to be distribution specific. Most often it will be www, or
www-data. The serivce user account is generally specified by the service
daemon management system configuration scripts for Apache/httpd (Systemd in
this case).


> What user is apache running as if started with python manage.py
> runserver?
>

It isn't. The runserver command is running its own bare-bones web server
that is built into Python/Django (WEBrick IIRC, or at least it was
previously). Only to be used for development, not for production.


> How do I assure that Apache is running as www-data?
>

Running ps -ef | grep -i '\(apache|http\)' should give you the user that
the processes (Apache and all of its children) are running as in the first
column.


> Do I need to start Apache with mod_wsgi-express --user www-data
> --group www-data or is python manage.py runserver good enough?
>

You should not be using either of those methods for a production
installation of your project. Configure Apache directly to reference
mod_wsgi.

https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/


>
> Answers to these questions would be very very helpful
>
> Gary R



Is there a specific reason that you installed a custom version of mod_wsgi?
Most distributions provide a 2.7 and 3.X compatible version of mod_wsgi
along with their Apache installations (or provide package installations for
mod_wsgi for each respective Python version). High-end installations with
node management and configuration control tend to use custom compiled
versions since they can manage them effectively. The rest of us peasants
are probably better off using the distribution packages until we figure out
what we're doing (myself included).

Out of curiosity, I logged into one of my Debian 8 boxen and verified that
this is the case:

$ apt-cache search mod-wsgi
libapache2-mod-wsgi - Python WSGI adapter module for Apache
libapache2-mod-wsgi-py3 - Python 3 WSGI adapter module for Apache

$ apt-cache showpkg libapache2-mod-wsgi-py3
Package: libapache2-mod-wsgi-py3
Versions:
4.3.0-1
(/var/lib/apt/lists/mirrors.ocf.berkeley.edu_debian_dists_jessie_main_binary-amd64_Packages)
 Description Language:
 File:
/var/lib/apt/lists/mirrors.ocf.berkeley.edu_debian_dists_jessie_main_binary-amd64_Packages
  MD5: 9804c7965adca269cbc58c4a8eb236d8
 Description Language: en
 File:
/var/lib/apt/lists/mirrors.ocf.berkeley.edu_debian_dists_jessie_main_i18n_Translation-en
  MD5: 9804c7965adca269cbc58c4a8eb236d8


Reverse Depends:
  apache2.2-common,libapache2-mod-wsgi-py3 3.4-2
  dms-wsgi,libapache2-mod-wsgi-py3
  apache2.2-common,libapache2-mod-wsgi-py3 3.4-2
Dependencies:
4.3.0-1 - libc6 (2 2.14) libpython3.4 (2 3.4.2~rc1) apache2-api-20120211 (0
(null)) python3 (2 3.4) python3 (3 3.5) libapache2-mod-wsgi (0 (null))
Provides:
4.3.0-1 - httpd-wsgi
Reverse Provides:


Looks like Debian 8 supports your version of Python (3.4.2) for mod_wsgi
out of the box, with no fussing around with Python 

Re: Apache2, mod_wsgi and django setup

2015-11-12 Thread Andrew Farrell
Others on here should jump in with help with your other questions but I
think you should find the answers to your first and third by running `ps
aux | grep apache` and looking at the first column. You might also find it
enlightening to run `ps auxf | grep apache -B 2`.

On Thu, Nov 12, 2015 at 4:34 PM, Gary Roach 
wrote:

> Setup for Django development system
>
> OS Debian Linux 8 (jessie) using systemd, not init.d
> Python 3.4.2
> Django 1.8.5
> Apache2 2.4.10 Debian (mmm-worker)
> mod_wsgi 4.3.0
> Postgresql 9.4.5
>
> Two virtual environments: archive (actual project) and mysite (django
> tutorial). Setup done with python3 -m venv . There seems to
> be some variation between this setup and the one using virtualenv.
> Confusing.
>
> pip3 install mod_wsgi in each environment
> Run mod_wsgi-express with install-module and setup-server for each.
>
> In /etc/apache2/envvars the following environmental variables are set.
> export APACHE_RUN_USER=www-data
> export APACHE_RUN_GROUP=www-data
>
> In /etc/apache2/apache2.conf the following environmental variables are
> used to set user and group.
> User ${APACHE_RUN_USER}
> Group ${APACHE_RUN_GROUP}
>
> But starting from within the project with mod_wsgi-express start-server
> gives:
>
> WARNING: When running as the 'root' user, it is required that the options
> '--user' and '--group' be specified to mod_wsgi-express.
>
> Starting with apachectl start or python manage.py runserver give no
> errors. Both servers work.
>
> Questions:
> What user is apache running as if started with apachectl?
> What user is apache running as if started with python manage.py
> runserver?
> How do I assure that Apache is running as www-data?
> Do I need to start Apache with mod_wsgi-express --user www-data
> --group www-data or is python manage.py runserver good enough?
>
> Answers to these questions would be very very helpful
>
> Gary R
>
> --
> 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+unsubscr...@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/564513EF.8050508%40verizon.net
> .
> 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+unsubscr...@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%2By5TLZf36UGOqm-8uWZDXXoXZcYqLxwABRnbPALMvYc_aoG1Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Apache2, mod_wsgi and django setup

2015-11-12 Thread Gary Roach

Setup for Django development system

OS Debian Linux 8 (jessie) using systemd, not init.d
Python 3.4.2
Django 1.8.5
Apache2 2.4.10 Debian (mmm-worker)
mod_wsgi 4.3.0
Postgresql 9.4.5

Two virtual environments: archive (actual project) and mysite (django 
tutorial). Setup done with python3 -m venv . There seems 
to be some variation between this setup and the one using virtualenv. 
Confusing.


pip3 install mod_wsgi in each environment
Run mod_wsgi-express with install-module and setup-server for each.

In /etc/apache2/envvars the following environmental variables are set.
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data

In /etc/apache2/apache2.conf the following environmental variables are 
used to set user and group.

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

But starting from within the project with mod_wsgi-express start-server 
gives:


WARNING: When running as the 'root' user, it is required that the 
options '--user' and '--group' be specified to mod_wsgi-express.


Starting with apachectl start or python manage.py runserver give no 
errors. Both servers work.


Questions:
What user is apache running as if started with apachectl?
What user is apache running as if started with python manage.py 
runserver?
How do I assure that Apache is running as www-data?
	Do I need to start Apache with mod_wsgi-express --user www-data --group 
www-data or is python manage.py runserver good enough?


Answers to these questions would be very very helpful

Gary R

--
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+unsubscr...@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/564513EF.8050508%40verizon.net.
For more options, visit https://groups.google.com/d/optout.


Re: problema con un select

2015-11-12 Thread miguel angel lopez mendo
--template-
 

{% extends 'base.html' %}
{% load staticfiles %}
{% block head_title %}
{% endblock %}



 Soni Compañia 




{% block style %}
h1 {
text-transform: uppercase;
  }
hr { 
  background-color: black;
  height: 5px; 
}

body{
margin: 0;
padding: 0;
}

a{
text-decoration: none;
}

.container  .dropdown {
  margin: 0 20px;
  vertical-align: top;
}

.dropdown {
  display: inline-block;
  position: relative;
  overflow: hidden;
  height: 28px;
  width: 150px;
  background: #f2f2f2;
  border: 1px solid;
  border-color: white #f7f7f7 whitesmoke;
  border-radius: 3px;
  
}

.dropdown:before, .dropdown:after {
  content: '';
  position: absolute;
  z-index: 2;
  top: 9px;
  right: 10px;
  width: 0;
  height: 0;
  border: 4px dashed;
  border-color: #88 transparent;
  pointer-events: none;
}

.dropdown:before {
  border-bottom-style: solid;
  border-top: none;
}

.dropdown:after {
  margin-top: 7px;
  border-top-style: solid;
  border-bottom: none;
}

.dropdown-select {
  position: relative;
  width: 130%;
  margin: 0;
  padding: 6px 8px 6px 10px;
  height: 28px;
  line-height: 14px;
  font-size: 12px;
  color: #62717a;
  text-shadow: 0 1px white;

  border: 0;
  border-radius: 0;
  -webkit-appearance: none;
}

.dropdown-select:focus {
  z-index: 3;
  width: 100%;
  color: #394349;
  outline: 2px solid #49aff2;
  outline: 2px solid -webkit-focus-ring-color;
  outline-offset: -2px;
}

.dropdown-select > option {
  margin: 3px;
  padding: 6px 8px;
  text-shadow: none;
  background: #f2f2f2;
  border-radius: 3px;
  cursor: pointer;
}


{% endblock %}


{% block content %}


 

  
El numero de registros totales son: {{ clientes.count }} 
El numero de registros por el medio uno son : {{ clientes2.count }}
El numero de registros por el medio dos son : {{ clientes3.count }}
El numero de registros por el medio dos son : {{ clientes4.count }}
Los medios son :{{medios}}

Medio: 
Selecciona una opcion 

 {% for medio in medios %}
 {{medio.nombre_medio}}
{% endfor %}




Periodo: 
Selecciona una opcion 
Periodo 1
Periodo 2
Periodo 3 


Filtrar









{% for letra in objects %}
{% for key, clientes in letra.items %}
   {{key}} 

{% for cliente in clientes %}
 Nombre del Cliente: {{ 
cliente.Nombre }} {{ cliente.Apellido}}
 Medio por el cual llego: {{ 
cliente.medio}} 
 
{% endfor %}

{% endfor %}
{% endfor %}

 

{% endblock %}


-view--
from django.shortcuts import render, Http404
from .models import Coche, CocheImage, Clientes, Medio
from datetime import *
import string


def search(request):
try:
q = request.GET.get('q')
except:
q = None

if q:
coche = Coche.objects.filter(titulo__icontains=q)
context = {'query': q, 'coche': coche}
template = 'products/results.html'
else:
template = 'home.html'
context = {}
return render(request, template, context)


def home(request):
products = Coche.objects.all()
template = 'home.html'
return render(request, template, locals())


def all(request):
products = Coche.objects.all()
template = 'products/all.html'
return render(request, template, locals())


def usados(request):
products = Coche.objects.filter(tipo='1')
template = 'products/usados.html'
return render(request, template, locals())


def solicitados(request):
products = Coche.objects.filter(tipo='2')
template = 'products/solicitados.html'
return render(request, template, locals())


def asignados(request):
hoy = date.today()
mes = datetime.now().month
year = datetime.now().year

# products =Coche.objects.filter(fecha = hoy,
#tipo='3',fecha__month= 11)

products = Coche.objects.filter(tipo='3')
template = 'products/asignados.html'
return render(request, template, locals())


def proceso(request):
products = Coche.objects.filter(tipo='4')

template = 'products/proceso.html'
return render(request, template, locals())


def recientes(request):
products = Coche.objects.filter()
template = 'products/proceso.html'
return render(request, template, locals())


def single(request, slug):
try:
product = Coche.objects.get(slug=slug)
images = CocheImage.objects.filter(product=product)
template = 'products/single.html'
return render(request, template, locals())
except:
raise Http404


def single2(request, slug):
try:
product = Clientes.objects.get(slug=slug)
template = 'products/Single_clientes.html'
return render(request, template, locals())
except:
raise Http404


def clientes(request):
clientes = Clientes.objects.order_by('Nombre')
clientes2 = Clientes.objects.order_by('Nombre').filter(medio='1')
clientes3 = Clientes.objects.order_by('Nombre').filter(medio='2')
clientes4 = Clientes.objects.order_by('Nombre').filter(medio='3')

 

Re: Custom user model password is not hashed

2015-11-12 Thread Andreas Kuhne
Try to debug and check what your password value is after the set_password()
statement.  Also have you checked the database after trying to create a
user with the new method? It should be hashed in the database. This is
stuff that should "just work" in django (it's regulated by the
AbstractBaseUser and is the same that I am using in a project).

You did restart the django shell after changing the code?

2015-11-12 16:44 GMT+01:00 Benjamin Smith :

> I have changed user.set_password(self.cleaned_data["password"]) to 
> user.set_password(password).
> But I am getting the same result.
>
> On Thu, Nov 12, 2015 at 8:57 PM, Andreas Kuhne  > wrote:
>
>> As aRkadeFR says, you seam to have mixed code there
>>
>> The row:
>> user.set_password(self.cleaned_data["password"])
>>
>> is taken from a form somewhere and won't work. It should instead be :
>> user.set_password(password)
>>
>> I suppose the password is going through to the create method via the
>> kwargs argument at the end of you create method. But if you change like I
>> said, everything should work.
>>
>>
>> Med vänliga hälsningar,
>>
>> Andréas Kühne
>> Software Development Manager
>> Suitopia Scandinavia AB
>>
>> 2015-11-12 16:20 GMT+01:00 aRkadeFR :
>>
>>> Hello,
>>>
>>> I don't quite get the code in your method: 'MyUserManager.create_user':
>>> user.set_password(self.cleaned_data["password"])
>>>
>>> You're in your Manager method but call self.cleaned_data ?
>>>
>>> You can set a breakpoint inside your method with pdb to see
>>> what's going on with your fields?
>>>
>>>
>>> On 11/12/2015 04:11 PM, Benjamin Smith wrote:
>>>
>>> I have my own custom User model, and its own Manger too.
>>>
>>> Models:
>>>
>>> class MyUser(AbstractBaseUser, PermissionsMixin):
>>> email = models.EmailField(max_length=255, unique=True)
>>> first_name = models.CharField(max_length=35)
>>> last_name = models.CharField(max_length=35)
>>> username = models.CharField(max_length=70, unique=True)
>>> date_of_birth = models.DateField()
>>> is_active = models.BooleanField(default=True)
>>> is_admin = models.BooleanField(default=False)
>>>
>>> @property
>>> def is_staff(self):
>>> return self.is_admin
>>>
>>> def get_full_name(self):
>>> return ('%s %s') % (self.first_name, self.last_name)
>>>
>>> def get_short_name(self):
>>> return self.username
>>>
>>> objects = MyUserManager()
>>> USERNAME_FIELD = 'email'
>>> REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
>>> 'date_of_birth']
>>>
>>>
>>> Manager:
>>>
>>> class MyUserManager(BaseUserManager):
>>> def create_user(self, email, first_name, last_name, username,
>>> date_of_birth, password=None, **kwargs):
>>> if not email:
>>> raise ValueError('User must have an email address')
>>>
>>> user = self.model(
>>> email=self.normalize_email(email),
>>> first_name=first_name,
>>> last_name=last_name,
>>> username=username,
>>> date_of_birth=date_of_birth,
>>> **kwargs
>>> )
>>> user.set_password(self.cleaned_data["password"])
>>> user.save(using=self._db)
>>> return user
>>>
>>> def create_superuser(self, email, first_name, last_name, username,
>>> date_of_birth, password, **kwargs):
>>> user = self.create_user(
>>> email,
>>> first_name=first_name,
>>> last_name=last_name,
>>> username=username,
>>> date_of_birth=date_of_birth,
>>> password=password,
>>> is_superuser=True,
>>> **kwargs
>>> )
>>> user.is_admin = True
>>> user.save(using=self._db)
>>> return user
>>>
>>>
>>> Everything works when creating a new user without any errors. But when I
>>> try to login I can't. So I checked the user's email and password to
>>> confirm. Then I noticed that the password is displayed as plain text (eg.
>>> *strongpassword)*, and when changed the admin form to get the hashed
>>> password using *ReadOnlyPasswordHashField()* I get an error inside the
>>> password field, even though I used *set_password()* for the Manger
>>> inside the *create_user()* function.
>>>
>>> *Invalid password format or unknown hashing algorithm*
>>>
>>>
>>> However, if I manually do *set_password('strongpassword')* for that
>>> user inside the console, then only the password is hashed. Could you please
>>> help me solve this problem. Thank 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+unsubscr...@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 

Re: Custom user model password is not hashed

2015-11-12 Thread Benjamin Smith
I have changed user.set_password(self.cleaned_data["password"]) to
user.set_password(password).
But I am getting the same result.

On Thu, Nov 12, 2015 at 8:57 PM, Andreas Kuhne 
wrote:

> As aRkadeFR says, you seam to have mixed code there
>
> The row:
> user.set_password(self.cleaned_data["password"])
>
> is taken from a form somewhere and won't work. It should instead be :
> user.set_password(password)
>
> I suppose the password is going through to the create method via the
> kwargs argument at the end of you create method. But if you change like I
> said, everything should work.
>
>
> Med vänliga hälsningar,
>
> Andréas Kühne
> Software Development Manager
> Suitopia Scandinavia AB
>
> 2015-11-12 16:20 GMT+01:00 aRkadeFR :
>
>> Hello,
>>
>> I don't quite get the code in your method: 'MyUserManager.create_user':
>> user.set_password(self.cleaned_data["password"])
>>
>> You're in your Manager method but call self.cleaned_data ?
>>
>> You can set a breakpoint inside your method with pdb to see
>> what's going on with your fields?
>>
>>
>> On 11/12/2015 04:11 PM, Benjamin Smith wrote:
>>
>> I have my own custom User model, and its own Manger too.
>>
>> Models:
>>
>> class MyUser(AbstractBaseUser, PermissionsMixin):
>> email = models.EmailField(max_length=255, unique=True)
>> first_name = models.CharField(max_length=35)
>> last_name = models.CharField(max_length=35)
>> username = models.CharField(max_length=70, unique=True)
>> date_of_birth = models.DateField()
>> is_active = models.BooleanField(default=True)
>> is_admin = models.BooleanField(default=False)
>>
>> @property
>> def is_staff(self):
>> return self.is_admin
>>
>> def get_full_name(self):
>> return ('%s %s') % (self.first_name, self.last_name)
>>
>> def get_short_name(self):
>> return self.username
>>
>> objects = MyUserManager()
>> USERNAME_FIELD = 'email'
>> REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
>> 'date_of_birth']
>>
>>
>> Manager:
>>
>> class MyUserManager(BaseUserManager):
>> def create_user(self, email, first_name, last_name, username,
>> date_of_birth, password=None, **kwargs):
>> if not email:
>> raise ValueError('User must have an email address')
>>
>> user = self.model(
>> email=self.normalize_email(email),
>> first_name=first_name,
>> last_name=last_name,
>> username=username,
>> date_of_birth=date_of_birth,
>> **kwargs
>> )
>> user.set_password(self.cleaned_data["password"])
>> user.save(using=self._db)
>> return user
>>
>> def create_superuser(self, email, first_name, last_name, username,
>> date_of_birth, password, **kwargs):
>> user = self.create_user(
>> email,
>> first_name=first_name,
>> last_name=last_name,
>> username=username,
>> date_of_birth=date_of_birth,
>> password=password,
>> is_superuser=True,
>> **kwargs
>> )
>> user.is_admin = True
>> user.save(using=self._db)
>> return user
>>
>>
>> Everything works when creating a new user without any errors. But when I
>> try to login I can't. So I checked the user's email and password to
>> confirm. Then I noticed that the password is displayed as plain text (eg.
>> *strongpassword)*, and when changed the admin form to get the hashed
>> password using *ReadOnlyPasswordHashField()* I get an error inside the
>> password field, even though I used *set_password()* for the Manger
>> inside the *create_user()* function.
>>
>> *Invalid password format or unknown hashing algorithm*
>>
>>
>> However, if I manually do *set_password('strongpassword')* for that user
>> inside the console, then only the password is hashed. Could you please help
>> me solve this problem. Thank 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+unsubscr...@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/CAM4YLWJNGdSj-rVAuhta_UA50Cjna8zg-c14FPxK%3DtdU49mngQ%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> aRkadeFR
>>
>> --
>> 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 

Re: problema con un select

2015-11-12 Thread miguel angel lopez mendo
No me queda .. 

El miércoles, 11 de noviembre de 2015, 13:34:13 (UTC-6), alan.avalosh 
escribió:
>
> En el método del view, no estás regresando la colección de objetos tipo 
> Medio.
>
> Sent from my iPhone
>
> On Nov 11, 2015, at 12:19 PM, miguel angel lopez mendo  > wrote:
>
> view
>
> def medios(request):
> medios = Medio.objects.filter()
> template = 'products/Clientes.html'
> print medios
> return render(request, template, locals())
>
>
> model-
>
> class Medio (models.Model):
> nombre_medio = models.CharField(max_length=50)
>
> def __unicode__(self):
> return  self.nombre_medio
>
>
> template--
> Selecciona una opcion 
>  {% for medio in medios %}
> {{ medios.nombre_medio }}
> {% endfor %}
>
> 
>
>
>
> No se cual es el error no me muestra los medios que tengo registrados 
>
> -- 
> 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...@googlegroups.com .
> To post to this group, send email to django...@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/d9d6474b-6046-4abc-b097-51f7b67b6429%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+unsubscr...@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/4bd3061e-831c-4df3-b388-18becbaf965e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom user model password is not hashed

2015-11-12 Thread Andreas Kuhne
As aRkadeFR says, you seam to have mixed code there

The row:
user.set_password(self.cleaned_data["password"])

is taken from a form somewhere and won't work. It should instead be :
user.set_password(password)

I suppose the password is going through to the create method via the kwargs
argument at the end of you create method. But if you change like I said,
everything should work.


Med vänliga hälsningar,

Andréas Kühne
Software Development Manager
Suitopia Scandinavia AB

2015-11-12 16:20 GMT+01:00 aRkadeFR :

> Hello,
>
> I don't quite get the code in your method: 'MyUserManager.create_user':
> user.set_password(self.cleaned_data["password"])
>
> You're in your Manager method but call self.cleaned_data ?
>
> You can set a breakpoint inside your method with pdb to see
> what's going on with your fields?
>
>
> On 11/12/2015 04:11 PM, Benjamin Smith wrote:
>
> I have my own custom User model, and its own Manger too.
>
> Models:
>
> class MyUser(AbstractBaseUser, PermissionsMixin):
> email = models.EmailField(max_length=255, unique=True)
> first_name = models.CharField(max_length=35)
> last_name = models.CharField(max_length=35)
> username = models.CharField(max_length=70, unique=True)
> date_of_birth = models.DateField()
> is_active = models.BooleanField(default=True)
> is_admin = models.BooleanField(default=False)
>
> @property
> def is_staff(self):
> return self.is_admin
>
> def get_full_name(self):
> return ('%s %s') % (self.first_name, self.last_name)
>
> def get_short_name(self):
> return self.username
>
> objects = MyUserManager()
> USERNAME_FIELD = 'email'
> REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
> 'date_of_birth']
>
>
> Manager:
>
> class MyUserManager(BaseUserManager):
> def create_user(self, email, first_name, last_name, username,
> date_of_birth, password=None, **kwargs):
> if not email:
> raise ValueError('User must have an email address')
>
> user = self.model(
> email=self.normalize_email(email),
> first_name=first_name,
> last_name=last_name,
> username=username,
> date_of_birth=date_of_birth,
> **kwargs
> )
> user.set_password(self.cleaned_data["password"])
> user.save(using=self._db)
> return user
>
> def create_superuser(self, email, first_name, last_name, username,
> date_of_birth, password, **kwargs):
> user = self.create_user(
> email,
> first_name=first_name,
> last_name=last_name,
> username=username,
> date_of_birth=date_of_birth,
> password=password,
> is_superuser=True,
> **kwargs
> )
> user.is_admin = True
> user.save(using=self._db)
> return user
>
>
> Everything works when creating a new user without any errors. But when I
> try to login I can't. So I checked the user's email and password to
> confirm. Then I noticed that the password is displayed as plain text (eg.
> *strongpassword)*, and when changed the admin form to get the hashed
> password using *ReadOnlyPasswordHashField()* I get an error inside the
> password field, even though I used *set_password()* for the Manger inside
> the *create_user()* function.
>
> *Invalid password format or unknown hashing algorithm*
>
>
> However, if I manually do *set_password('strongpassword')* for that user
> inside the console, then only the password is hashed. Could you please help
> me solve this problem. Thank 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+unsubscr...@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/CAM4YLWJNGdSj-rVAuhta_UA50Cjna8zg-c14FPxK%3DtdU49mngQ%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> aRkadeFR
>
> --
> 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+unsubscr...@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/5644AE3A.5050609%40arkade.info
> 

Re: Custom user model password is not hashed

2015-11-12 Thread Thorsten Sanders

If you wanna set the password yourself you need to generate it:

https://docs.djangoproject.com/en/1.8/topics/auth/passwords/

scroll down to the bottom and have a lookt at make_password



Am 12.11.2015 um 16:11 schrieb Benjamin Smith:

I have my own custom User model, and its own Manger too.

Models:

class MyUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=255, unique=True)
first_name = models.CharField(max_length=35)
last_name = models.CharField(max_length=35)
username = models.CharField(max_length=70, unique=True)
date_of_birth = models.DateField()
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)

@property
def is_staff(self):
return self.is_admin

def get_full_name(self):
return ('%s %s') % (self.first_name, self.last_name)

def get_short_name(self):
return self.username

objects = MyUserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
'date_of_birth']


Manager:

class MyUserManager(BaseUserManager):
def create_user(self, email, first_name, last_name, username,
date_of_birth, password=None, **kwargs):
if not email:
raise ValueError('User must have an email address')

user = self.model(
email=self.normalize_email(email),
first_name=first_name,
last_name=last_name,
username=username,
date_of_birth=date_of_birth,
**kwargs
)
user.set_password(self.cleaned_data["password"])
user.save(using=self._db)
return user

def create_superuser(self, email, first_name, last_name,
username, date_of_birth, password, **kwargs):
user = self.create_user(
email,
first_name=first_name,
last_name=last_name,
username=username,
date_of_birth=date_of_birth,
password=password,
is_superuser=True,
**kwargs
)
user.is_admin = True
user.save(using=self._db)
return user


Everything works when creating a new user without any errors. But when 
I try to login I can't. So I checked the user's email and password to 
confirm. Then I noticed that the password is displayed as plain text 
(eg. *strongpassword)*, and when changed the admin form to get the 
hashed password using *ReadOnlyPasswordHashField()* I get an error 
inside the password field, even though I used *set_password()* for the 
Manger inside the *create_user()* function.


/Invalid password format or unknown hashing algorithm/


However, if I manually do *set_password('strongpassword')* for that 
user inside the console, then only the password is hashed. Could you 
please help me solve this problem. Thank 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+unsubscr...@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/CAM4YLWJNGdSj-rVAuhta_UA50Cjna8zg-c14FPxK%3DtdU49mngQ%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+unsubscr...@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/5644AF6C.1090304%40gmx.net.
For more options, visit https://groups.google.com/d/optout.


Re: Custom user model password is not hashed

2015-11-12 Thread aRkadeFR

Hello,

I don't quite get the code in your method: 'MyUserManager.create_user':
user.set_password(self.cleaned_data["password"])

You're in your Manager method but call self.cleaned_data ?

You can set a breakpoint inside your method with pdb to see
what's going on with your fields?


On 11/12/2015 04:11 PM, Benjamin Smith wrote:

I have my own custom User model, and its own Manger too.

Models:

class MyUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=255, unique=True)
first_name = models.CharField(max_length=35)
last_name = models.CharField(max_length=35)
username = models.CharField(max_length=70, unique=True)
date_of_birth = models.DateField()
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)

@property
def is_staff(self):
return self.is_admin

def get_full_name(self):
return ('%s %s') % (self.first_name, self.last_name)

def get_short_name(self):
return self.username

objects = MyUserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
'date_of_birth']


Manager:

class MyUserManager(BaseUserManager):
def create_user(self, email, first_name, last_name, username,
date_of_birth, password=None, **kwargs):
if not email:
raise ValueError('User must have an email address')

user = self.model(
email=self.normalize_email(email),
first_name=first_name,
last_name=last_name,
username=username,
date_of_birth=date_of_birth,
**kwargs
)
user.set_password(self.cleaned_data["password"])
user.save(using=self._db)
return user

def create_superuser(self, email, first_name, last_name,
username, date_of_birth, password, **kwargs):
user = self.create_user(
email,
first_name=first_name,
last_name=last_name,
username=username,
date_of_birth=date_of_birth,
password=password,
is_superuser=True,
**kwargs
)
user.is_admin = True
user.save(using=self._db)
return user


Everything works when creating a new user without any errors. But when 
I try to login I can't. So I checked the user's email and password to 
confirm. Then I noticed that the password is displayed as plain text 
(eg. *strongpassword)*, and when changed the admin form to get the 
hashed password using *ReadOnlyPasswordHashField()* I get an error 
inside the password field, even though I used *set_password()* for the 
Manger inside the *create_user()* function.


/Invalid password format or unknown hashing algorithm/


However, if I manually do *set_password('strongpassword')* for that 
user inside the console, then only the password is hashed. Could you 
please help me solve this problem. Thank 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+unsubscr...@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/CAM4YLWJNGdSj-rVAuhta_UA50Cjna8zg-c14FPxK%3DtdU49mngQ%40mail.gmail.com 
.

For more options, visit https://groups.google.com/d/optout.


--
aRkadeFR

--
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+unsubscr...@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/5644AE3A.5050609%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Custom user model password is not hashed

2015-11-12 Thread Benjamin Smith
I have my own custom User model, and its own Manger too.

Models:

class MyUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=255, unique=True)
first_name = models.CharField(max_length=35)
last_name = models.CharField(max_length=35)
username = models.CharField(max_length=70, unique=True)
date_of_birth = models.DateField()
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)

@property
def is_staff(self):
return self.is_admin

def get_full_name(self):
return ('%s %s') % (self.first_name, self.last_name)

def get_short_name(self):
return self.username

objects = MyUserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name', 'username',
'date_of_birth']


Manager:

class MyUserManager(BaseUserManager):
def create_user(self, email, first_name, last_name, username,
date_of_birth, password=None, **kwargs):
if not email:
raise ValueError('User must have an email address')

user = self.model(
email=self.normalize_email(email),
first_name=first_name,
last_name=last_name,
username=username,
date_of_birth=date_of_birth,
**kwargs
)
user.set_password(self.cleaned_data["password"])
user.save(using=self._db)
return user

def create_superuser(self, email, first_name, last_name, username,
date_of_birth, password, **kwargs):
user = self.create_user(
email,
first_name=first_name,
last_name=last_name,
username=username,
date_of_birth=date_of_birth,
password=password,
is_superuser=True,
**kwargs
)
user.is_admin = True
user.save(using=self._db)
return user


Everything works when creating a new user without any errors. But when I
try to login I can't. So I checked the user's email and password to
confirm. Then I noticed that the password is displayed as plain text (eg.
*strongpassword)*, and when changed the admin form to get the hashed
password using *ReadOnlyPasswordHashField()* I get an error inside the
password field, even though I used *set_password()* for the Manger inside
the *create_user()* function.

*Invalid password format or unknown hashing algorithm*


However, if I manually do *set_password('strongpassword')* for that user
inside the console, then only the password is hashed. Could you please help
me solve this problem. Thank 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+unsubscr...@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/CAM4YLWJNGdSj-rVAuhta_UA50Cjna8zg-c14FPxK%3DtdU49mngQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Disable autocomplete in admin field

2015-11-12 Thread Ezequiel Bertti
Great!

If you prefer to write some code and not implement new class. What you
thing to override the *get_form *method on model admin?

https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_form

def get_form(self, request, obj=None, **kwargs):
form = super(EmpresaAdmin, self).get_form(request, obj, **kwargs)
form.fields['username'].widget.attrs['autocomplete'] = 'off'
return form



On Thu, Nov 12, 2015 at 11:41 AM, Erik Cederstrand <
erik+li...@cederstrand.dk> wrote:

> Hi Ezequeil,
>
> Thanks for the explanation! This worked, but defining a new widget from
> scratch meant that I lost the other helpful attributes (length, class etc.)
> that the admin adds for me. Instead, in the DRY spirit, I opted to just add
> this one extra attribute. Here's the relevant code:
>
> class MyAdminForm(forms.ModelForm):
> def __init__(self, *args, **kwargs):
> super().__init__(*args, **kwargs)
> self.fields['username'].widget.attrs['autocomplete'] = 'off'
>
> Erik
>
>
> > Den 12. nov. 2015 kl. 13.33 skrev Ezequiel Bertti :
> >
> >
> > In html:
> >
> > 
> >
> > Um django you need to create a form for your model and set a field to
> username. In this field, set a widget like this:
> >
> > username = forms.CharField(widget=forms.TextInput(attrs={'autocomplete':
> 'off'}))
> >
> > Now you set a form on your model admin, like this example
> >
> >
> https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#adding-custom-validation-to-the-admin
> >
> >
> > On Thu, Nov 12, 2015 at 8:46 AM, Erik Cederstrand <
> erik+li...@cederstrand.dk> wrote:
> > Hello,
> >
> > I have a model with a CharField named "username". When I edit a model
> instance in the admin, my browser likes to autocomplete the contents of the
> "username" field with my username for the Django site, regardless of what
> was entered previously.
> >
> > Is there anything I can do to disable this behaviour, except for
> renaming the field to
> "username_PLEASE_DONT_AUTOCOMPLETE_SAFARI_IM_LOOKING_AT_YOU"?
> >
> > Thanks,
> > Erik
> >
> > --
> > 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+unsubscr...@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/DFF8D42F-D4F1-4686-942E-A906F919488B%40cederstrand.dk
> .
> > For more options, visit https://groups.google.com/d/optout.
> >
> >
> >
> > --
> > Ezequiel Bertti
> > E-Mail: eber...@gmail.com
> > Cel: (21) 99188-4860
> >
> > --
> > 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+unsubscr...@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/CACrQMYrb9aDDD1L%2BFvOtn90M6YDEuaVODoO-JWPqF0E5YiS9UA%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+unsubscr...@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/B74769F9-9905-4998-AF98-2461854321C1%40cederstrand.dk
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Ezequiel Bertti
E-Mail: eber...@gmail.com
Cel: (21) 99188-4860

-- 
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+unsubscr...@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/CACrQMYq36YQHB%3D%2BT-sqKbQ1hNMMOqJ4CBJHZj_Nmgp6DLq6a_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Domain Driven Development

2015-11-12 Thread Vinicius Assef
Yes, and you should.

Note the "domain objects" cited from the book doesn't mean "model objects". 
In an active record model (as in Django) it can be a bit confusing, but you 
should have the so called Business Objects. It is what the book calls 
"domain objects". They are objects that map the "problem domain".

They are not models, as the Active Record lead us to think of. They are 
classes that "see the big picture". They use model classes and eventually 
other Business Objects classes, too.

So, this arrangement to guarantee integrity should lay not in model 
classes. Basically, the Active Record pattern maps one instance of the 
object to a table row and it has some drawbacks. For instance, an order 
without items is not an order at all. So, how to solve it using Active 
Record?

You don't. The pattern is not well suited for this case.

To make this in a proper way, you should create an object Order (not a 
model instance!), other object OrderItem and assure your rules go through 
Order. It's a basic entity relationship, with a strong and a weak entity. 
An OrderItem doesn't exist without an Order. So, you need an structure to 
represent a "full order" that don't map directly to a table row.

You should separate this in domain model objects. Yes, it looks like Java. 
But actually, it's design pattern.

I recommend you the talk "Architecture: The Lost Years", from Uncle 
Bob: https://www.youtube.com/watch?v=HhNIttd87xs

This article 
(http://blog.codefx.org/design/architecture/architecture-lost-years/) makes 
some analysis on the talk.

--
Vinicius Assef.


On Wednesday, 11 November 2015 20:46:15 UTC-2, Alex Newman wrote:
>
> I almost hate to bring this up, but we are reading Eric Evan's book 
> "Domain Driven Development" at my company in our technical bookclub and 
> some techniques in the book seem to be hard to apply in DJango. The main 
> one being the notion of aggregations:
>
> From  http://martinfowler.com/bliki/DDD_Aggregate.html
> "Aggregate is a pattern in Domain-Driven Design. A DDD aggregate is a 
> cluster of domain objects that can be treated as a single unit. An example 
> may be an order and its line-items, these will be separate objects, but 
> it's useful to treat the order (together with its line items) as a single 
> aggregate.
>
> An aggregate will have one of its component objects be the aggregate root. 
> Any references from outside the aggregate should only go to the aggregate 
> root. The root can thus ensure the integrity of the aggregate as a whole."
>
> Can we actually enforce this in django?
>

-- 
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+unsubscr...@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/e3526a83-fbc4-4746-a389-4cc8426e7565%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Disable autocomplete in admin field

2015-11-12 Thread Erik Cederstrand
Hi Ezequeil,

Thanks for the explanation! This worked, but defining a new widget from scratch 
meant that I lost the other helpful attributes (length, class etc.) that the 
admin adds for me. Instead, in the DRY spirit, I opted to just add this one 
extra attribute. Here's the relevant code:

class MyAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['username'].widget.attrs['autocomplete'] = 'off'

Erik


> Den 12. nov. 2015 kl. 13.33 skrev Ezequiel Bertti :
> 
> 
> In html:
> 
> 
> 
> Um django you need to create a form for your model and set a field to 
> username. In this field, set a widget like this:
> 
> username = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 
> 'off'}))
> 
> Now you set a form on your model admin, like this example
> 
> https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#adding-custom-validation-to-the-admin
> 
> 
> On Thu, Nov 12, 2015 at 8:46 AM, Erik Cederstrand  
> wrote:
> Hello,
> 
> I have a model with a CharField named "username". When I edit a model 
> instance in the admin, my browser likes to autocomplete the contents of the 
> "username" field with my username for the Django site, regardless of what was 
> entered previously.
> 
> Is there anything I can do to disable this behaviour, except for renaming the 
> field to "username_PLEASE_DONT_AUTOCOMPLETE_SAFARI_IM_LOOKING_AT_YOU"?
> 
> Thanks,
> Erik
> 
> --
> 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+unsubscr...@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/DFF8D42F-D4F1-4686-942E-A906F919488B%40cederstrand.dk.
> For more options, visit https://groups.google.com/d/optout.
> 
> 
> 
> -- 
> Ezequiel Bertti
> E-Mail: eber...@gmail.com
> Cel: (21) 99188-4860
> 
> -- 
> 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+unsubscr...@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/CACrQMYrb9aDDD1L%2BFvOtn90M6YDEuaVODoO-JWPqF0E5YiS9UA%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+unsubscr...@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/B74769F9-9905-4998-AF98-2461854321C1%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: TemplateSyntaxError: 'subpackage.echo' is not a valid tag library

2015-11-12 Thread Jose Paul
I am just running DJango 1.8 test cases ,here is start of the error trace .

=
ERROR: test_load06 (template_tests.syntax_tests.test_load.LoadTagTests)
--
Traceback (most recent call last):
  File 
"C:\Users\IBM_ADMIN\PythonWorkspace\DJangoTestCases\src\DJangoTestCases\tests\template_tests\utils.py",
 
line 117, in inner
func(self)
  File "C:\Python27\lib\site-packages\django\test\utils.py", line 196, in 
inner
return test_func(*args, **kwargs)
  File 
"C:\Users\IBM_ADMIN\PythonWorkspace\DJangoTestCases\src\DJangoTestCases\tests\template_tests\utils.py",
 
line 62, in inner
func(self)
  File 
"C:\Users\IBM_ADMIN\PythonWorkspace\DJangoTestCases\src\DJangoTestCases\tests\template_tests\syntax_tests\test_load.py",
 
line 39, in test_load06
output = self.engine.render_to_string('load06')
  File "C:\Python27\lib\site-packages\django\template\engine.py", line 208, 
in render_to_string
   

On Thursday, November 12, 2015 at 12:31:40 AM UTC+5:30, James Schneider 
wrote:
>
>
> On Nov 11, 2015 4:33 AM, "Jose Paul"  
> wrote:
> >
> >getting following error ,can someone help me to understand this 
> >
> > .
> > compiled_result = compile_func(self, token)
> >   File "C:\Python27\lib\site-packages\django\template\defaulttags.py", 
> line 1140, in load
> > (taglib, e))
> > TemplateSyntaxError: 'subpackage.echo' is not a valid tag library: 
> Template library subpackage.echo not found, tried 
> django.templatetags.subpackage.echo
> >
> > -- 
>
> What does the template line look like that it's throwing that error? Do 
> you have something like {% subpackage.echo %} in your template?
>
> -James
>

-- 
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+unsubscr...@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/c4afae45-ee41-4aec-a391-728a2459faf4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


TemplateDoesNotExist: first/test.html DJango 1.8

2015-11-12 Thread Jose Paul
I am getting several TemplateDoesNotExist .like below .

==
ERROR: test_pickling 
(template_tests.test_response.SimpleTemplateResponseTest)
--
Traceback (most recent call last):
  File 
"C:\Users\IBM_ADMIN\PythonWorkspace\DJangoTestCases\src\DJangoTestCases\tests\template_tests\test_response.py",
 
line 178, in test_pickling
response.render()
  File "C:\Python27\lib\site-packages\django\template\response.py", line 
158, in render
self.content = self.rendered_content
  File "C:\Python27\lib\site-packages\django\template\response.py", line 
133, in rendered_content
template = self._resolve_template(self.template_name)
  File "C:\Python27\lib\site-packages\django\template\response.py", line 
88, in _resolve_template
new_template = self.resolve_template(template)
  File "C:\Python27\lib\site-packages\django\template\response.py", line 
80, in resolve_template
return loader.get_template(template, using=self.using)
  File "C:\Python27\lib\site-packages\django\template\loader.py", line 46, 
in get_template
raise TemplateDoesNotExist(template_name)
TemplateDoesNotExist: first/test.html

Here is my setting.py ,seems I am missing something here .

BASE_TEST_DIR = os.path.join(BASE_DIR,'tests')

 
TEMPATE_TESTS = os.path.join(BASE_TEST_DIR,'template_tests')
TEMPATE_LODER=os.path.join(BASE_TEST_DIR,'template_loader')
TEMPATE_BACKENDS=os.path.join(BASE_TEST_DIR,'template_backends')
TEST_UTILS=os.path.join(BASE_TEST_DIR,'test_utils')
TEST_CLIENT_REGRESS=os.path.join(BASE_TEST_DIR,'test_client_regress')

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [ os.path.join(BASE_TEST_DIR, 'templates'), 
 os.path.join(TEMPATE_BACKENDS, 'templates'),
 os.path.join(TEMPATE_TESTS, 'templates'),
 os.path.join(TEST_UTILS, 'templates'),
 os.path.join(TEST_CLIENT_REGRESS, 'templates'),
 os.path.join(TEMPATE_LODER, 'templates'),],
'APP_DIRS': True,
'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',
],
},
},
]


I can see the " templates" folder in  following path .Following variables 
are initialized correctly .
All these folders have " templates" folder .
 
TEMPATE_TESTS = os.path.join(BASE_TEST_DIR,'template_tests')
TEMPATE_LODER=os.path.join(BASE_TEST_DIR,'template_loader')
TEMPATE_BACKENDS=os.path.join(BASE_TEST_DIR,'template_backends')
TEST_UTILS=os.path.join(BASE_TEST_DIR,'test_utils')
TEST_CLIENT_REGRESS=os.path.join(BASE_TEST_DIR,'test_client_regress')

Please help 


-- 
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+unsubscr...@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/08d6c2fe-c8be-465c-9fba-e93b105d1ef7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Disable autocomplete in admin field

2015-11-12 Thread Ezequiel Bertti
In html:



Um django you need to create a form for your model and set a field to
username. In this field, set a widget like this:

username = forms.CharField(widget=forms.TextInput(attrs={'autocomplete':
'off'}))


Now you set a form on your model admin, like this example

https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#adding-custom-validation-to-the-admin


On Thu, Nov 12, 2015 at 8:46 AM, Erik Cederstrand  wrote:

> Hello,
>
> I have a model with a CharField named "username". When I edit a model
> instance in the admin, my browser likes to autocomplete the contents of the
> "username" field with my username for the Django site, regardless of what
> was entered previously.
>
> Is there anything I can do to disable this behaviour, except for renaming
> the field to "username_PLEASE_DONT_AUTOCOMPLETE_SAFARI_IM_LOOKING_AT_YOU"?
>
> Thanks,
> Erik
>
> --
> 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+unsubscr...@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/DFF8D42F-D4F1-4686-942E-A906F919488B%40cederstrand.dk
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Ezequiel Bertti
E-Mail: eber...@gmail.com
Cel: (21) 99188-4860

-- 
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+unsubscr...@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/CACrQMYrb9aDDD1L%2BFvOtn90M6YDEuaVODoO-JWPqF0E5YiS9UA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Cannot assign object: instance isn't saved in the (wrong?) database

2015-11-12 Thread Julien Delafontaine
Hello,

I have multiple databases, so in my queries I must exploit the `using` 
keyword (even if here I consider only **one** of them). 
Now in `MY_DB`, I want to create a `User` that has a reference to a 
`People` entry - a different table in the **same** database. I do

person = People(firstname=firstname, lastname=lastname)
person.save(using=MY_DB)

newuser = User(username=username, person=person)
newuser.save(using=MY_DB)

But although I explicitly saved `person`, it tells me

Cannot assign "": "People" instance isn't saved 
in the database.

because, I believe, it looks into the 'default' database for the `person` I 
saved, and does not find it. How can I specify that the foreign key 
relationship concerns `MY_DB` ?


I also posted my question there but without success yet : 
http://stackoverflow.com/questions/33667668/django-cannot-assign-object-instance-isnt-saved-in-the-wrong-database

-- 
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+unsubscr...@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/c4d78478-20bb-443b-87b2-53b605ef8b51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to get logged username in template

2015-11-12 Thread Dariusz Mysior
Thanks for both advice. I am not advanced programmer sow I use the simplest 
solution on this moment this first one Andréas Kühne. Thanks it works!

W dniu czwartek, 12 listopada 2015 08:46:06 UTC+1 użytkownik Dariusz Mysior 
napisał:
>
> I am using Django 1.8 with Python 3.4 I had no idea why my template 
> doesn't show my username on template profile.html :/
>
>
> profile.py
>
>
> {% load staticfiles %}
>
> 
>
> {% block content %}
> My profile
> {{ request.user.username }}
> {% endblock %}
>
>
> views.py
>
>
> from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
> from django.shortcuts import render_to_response
> from django.http import  HttpResponseRedirect
> from django.core.context_processors import csrf
> from django.contrib.auth import authenticate, login
>
>
> def login_view(request):
>
> if request.method == 'POST':
> username = request.POST['username']
> password = request.POST['password']
> user = authenticate(username=username, password=password)
> if user is not None:
> if user.is_active:
> login(request, user)
> return HttpResponseRedirect('/accounts/profile')
> else:
> # Return a 'disabled account' error message
> ...
> pass
> else:
> # Return an 'invalid login' error message.
> pass
> form = AuthenticationForm()
> args = {}
> args.update(csrf(request))
> args['form']= AuthenticationForm()
> return render_to_response('accounts/login.html', args)
>
> def my_view(request):
> username = request.POST['username']
> password = request.POST['password']
> user = authenticate(username=username, password=password)
> if user is not None:
> print(request.user)
> if user.is_active:
> login(request, user)
> return HttpResponseRedirect('/accounts/profile')
> else:
> # Return a 'disabled account' error message
> ...
> else:
> # Return an 'invalid login' error message.
> ...
> def profile(request):
> username = request.user.username
> return render_to_response('accounts/profile.html', username)
>
> def register_user(request):
> if request.method == 'POST':
> form = UserCreationForm(request.POST)
> if form.is_valid():
> form.save()
> return HttpResponseRedirect('/accounts/register_success')
> args = {}
> args.update(csrf(request))
> args['form']= UserCreationForm()
> return render_to_response('accounts/register_user.html', args)
>
> def register_success(request):
> return render_to_response('accounts/register_success.html')
>
>
>
>

-- 
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+unsubscr...@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/2b355828-bbfd-4ffd-a8c4-ab0001f42f68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Disable autocomplete in admin field

2015-11-12 Thread Erik Cederstrand
Hello,

I have a model with a CharField named "username". When I edit a model instance 
in the admin, my browser likes to autocomplete the contents of the "username" 
field with my username for the Django site, regardless of what was entered 
previously.

Is there anything I can do to disable this behaviour, except for renaming the 
field to "username_PLEASE_DONT_AUTOCOMPLETE_SAFARI_IM_LOOKING_AT_YOU"?

Thanks,
Erik

-- 
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+unsubscr...@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/DFF8D42F-D4F1-4686-942E-A906F919488B%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: DoesNotExist: Group matching query does not exist.

2015-11-12 Thread James Schneider
>   File
"/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line
334, in get
>
> self.model._meta.object_name
>
> DoesNotExist: Group matching query does not exist.
>
>
> Can someone help me ?
>

BTW, this is a standard exception raised by Django for queryset operations
that act on single objects that are not found, most commonly for .get(). If
there's a chance you'll hit this during normal operation, you'll need to
catch the exception and handle it accordingly, or it will turn into a 500
error in the browser.

https://docs.djangoproject.com/en/1.8/ref/models/instances/#doesnotexist

-James

-- 
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+unsubscr...@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%2BciV41LP3nNEazc-pxtp0snR3C9H%2Bi%2BUoJNo4Wi7P%3DY%3DDaA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to get logged username in template

2015-11-12 Thread Dan Tagg
I would recommend using allauth
http://django-allauth.readthedocs.org/en/latest/templates.html. It has
template tags for adding all that info, creates pages for logging in, picks
up your base template etc etc.

Dan

On 12 November 2015 at 08:57, Andreas Kuhne 
wrote:

> Hi,
>
> First of all, you are using request.user.username and not username in your
> template. If you want the username to be accessed via the "username"
> variable. You should write this in your view:
>
> def profile(request):
> return render_to_response('accounts/profile.html', {'username': 
> request.user.username})
>
> And then in your template use the following code:
>
> {{ username }}
>
>
> However if you want to use the request object you should use the
> RequestContext context when rendering the page. See
> https://docs.djangoproject.com/en/1.8/ref/templates/api/#subclassing-context-requestcontext
>
> Also because you are using django 1.8, I would recommend that you start
> using class based views instead of view functions. But that's just my
> preference :-)
>
> Regards,
>
> Andréas
>
>
> 2015-11-12 8:46 GMT+01:00 Dariusz Mysior :
>
>> I am using Django 1.8 with Python 3.4 I had no idea why my template
>> doesn't show my username on template profile.html :/
>>
>>
>> profile.py
>>
>>
>> {% load staticfiles %}
>>
>> 
>>
>> {% block content %}
>> My profile
>> {{ request.user.username }}
>> {% endblock %}
>>
>>
>> views.py
>>
>>
>> from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
>> from django.shortcuts import render_to_response
>> from django.http import  HttpResponseRedirect
>> from django.core.context_processors import csrf
>> from django.contrib.auth import authenticate, login
>>
>>
>> def login_view(request):
>>
>> if request.method == 'POST':
>> username = request.POST['username']
>> password = request.POST['password']
>> user = authenticate(username=username, password=password)
>> if user is not None:
>> if user.is_active:
>> login(request, user)
>> return HttpResponseRedirect('/accounts/profile')
>> else:
>> # Return a 'disabled account' error message
>> ...
>> pass
>> else:
>> # Return an 'invalid login' error message.
>> pass
>> form = AuthenticationForm()
>> args = {}
>> args.update(csrf(request))
>> args['form']= AuthenticationForm()
>> return render_to_response('accounts/login.html', args)
>>
>> def my_view(request):
>> username = request.POST['username']
>> password = request.POST['password']
>> user = authenticate(username=username, password=password)
>> if user is not None:
>> print(request.user)
>> if user.is_active:
>> login(request, user)
>> return HttpResponseRedirect('/accounts/profile')
>> else:
>> # Return a 'disabled account' error message
>> ...
>> else:
>> # Return an 'invalid login' error message.
>> ...
>> def profile(request):
>> username = request.user.username
>> return render_to_response('accounts/profile.html', username)
>>
>> def register_user(request):
>> if request.method == 'POST':
>> form = UserCreationForm(request.POST)
>> if form.is_valid():
>> form.save()
>> return HttpResponseRedirect('/accounts/register_success')
>> args = {}
>> args.update(csrf(request))
>> args['form']= UserCreationForm()
>> return render_to_response('accounts/register_user.html', args)
>>
>> def register_success(request):
>> return render_to_response('accounts/register_success.html')
>>
>>
>>
>> --
>> 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+unsubscr...@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/88ec2289-59b6-41a3-a1d7-c41be3fc0b4b%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+unsubscr...@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
> 

Re: How to get logged username in template

2015-11-12 Thread Andreas Kuhne
Hi,

First of all, you are using request.user.username and not username in your
template. If you want the username to be accessed via the "username"
variable. You should write this in your view:

def profile(request):
return render_to_response('accounts/profile.html', {'username':
request.user.username})

And then in your template use the following code:

{{ username }}


However if you want to use the request object you should use the
RequestContext context when rendering the page. See
https://docs.djangoproject.com/en/1.8/ref/templates/api/#subclassing-context-requestcontext

Also because you are using django 1.8, I would recommend that you start
using class based views instead of view functions. But that's just my
preference :-)

Regards,

Andréas

2015-11-12 8:46 GMT+01:00 Dariusz Mysior :

> I am using Django 1.8 with Python 3.4 I had no idea why my template
> doesn't show my username on template profile.html :/
>
>
> profile.py
>
>
> {% load staticfiles %}
>
> 
>
> {% block content %}
> My profile
> {{ request.user.username }}
> {% endblock %}
>
>
> views.py
>
>
> from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
> from django.shortcuts import render_to_response
> from django.http import  HttpResponseRedirect
> from django.core.context_processors import csrf
> from django.contrib.auth import authenticate, login
>
>
> def login_view(request):
>
> if request.method == 'POST':
> username = request.POST['username']
> password = request.POST['password']
> user = authenticate(username=username, password=password)
> if user is not None:
> if user.is_active:
> login(request, user)
> return HttpResponseRedirect('/accounts/profile')
> else:
> # Return a 'disabled account' error message
> ...
> pass
> else:
> # Return an 'invalid login' error message.
> pass
> form = AuthenticationForm()
> args = {}
> args.update(csrf(request))
> args['form']= AuthenticationForm()
> return render_to_response('accounts/login.html', args)
>
> def my_view(request):
> username = request.POST['username']
> password = request.POST['password']
> user = authenticate(username=username, password=password)
> if user is not None:
> print(request.user)
> if user.is_active:
> login(request, user)
> return HttpResponseRedirect('/accounts/profile')
> else:
> # Return a 'disabled account' error message
> ...
> else:
> # Return an 'invalid login' error message.
> ...
> def profile(request):
> username = request.user.username
> return render_to_response('accounts/profile.html', username)
>
> def register_user(request):
> if request.method == 'POST':
> form = UserCreationForm(request.POST)
> if form.is_valid():
> form.save()
> return HttpResponseRedirect('/accounts/register_success')
> args = {}
> args.update(csrf(request))
> args['form']= UserCreationForm()
> return render_to_response('accounts/register_user.html', args)
>
> def register_success(request):
> return render_to_response('accounts/register_success.html')
>
>
>
> --
> 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+unsubscr...@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/88ec2289-59b6-41a3-a1d7-c41be3fc0b4b%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+unsubscr...@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/CALXYUbkQvGe%2B1%3DDAc6A%3DMv4S_wYSYjF_Nzcnt3P9Q%3DU%3DJ%2BtZ6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: DoesNotExist: Group matching query does not exist.

2015-11-12 Thread Robin Fourcade
Thanks for your reply,
It was in the DB but, I don't know why, I had this issue. I made the 
migration a second time and this time, it worked.

Thanks,
Robin.

-- Solved.

-- 
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+unsubscr...@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/8055f2f7-4b9d-4750-a8d8-6605bdad23d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.