help me to fix this issue with database connection

2019-08-28 Thread leb dev
i have a django project that need to be connected to MS SQL Server  i am 
using *pyodbc package.*

*once i run the program the system display the below error:*

djago.db.utils.operationalError:('08001','[08001] [microsoft][odbc sql 
server driver]neither dsn nor server keyword supplied (0) 
(sqldriverconnect); [08001] [microsoft][odbc sql server driver] Invalid 
connection string attribute (0)')

where is the error and how to fix it ?

from django.shortcuts import render
import pyodbc

def connect(request):
conn = pyodbc.connect(
'Driver={SQL Server};'
'Server=ip address;'
'Database=I-Base_beSQL;'
'Trusted_Connection=yes;'

)


cursor = conn.cursor()
c = cursor.execute('SELECT "first name" FROM Person   WHERE id = 2 ')

return render (request,'connect.html',{"c":c})

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4bdca932-9293-409e-a144-ef535d138422%40googlegroups.com.


Re: Django sockets

2019-08-28 Thread Suraj Thapa FC
Thanks i did it with Django channels

On Wed, 28 Aug, 2019, 7:20 PM nm, 
wrote:

>
> Perhaps you're looking for Django Channels?
> 
>
> On Tuesday, 27 August 2019 15:08:47 UTC+2, Suraj Thapa FC wrote:
>>
>> Anyone know making chat app using sockets in rest api
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9a45875f-a538-4489-a486-4ccdb3be71ab%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPjsHcHB4FooJgLToNeH%3DSfWEBeiOtx8%3DTxUUU5poo6eGEH6Vg%40mail.gmail.com.


PasswordResetDoneView not using custom template in Django

2019-08-28 Thread siva reddy


PasswordResetDoneView.as_view is not loading custom template I'm using 
Django 2.2 version

I have created a custom template and add the path to the accounts app URL


url(r'^reset_password/done/$',PasswordResetDoneView.as_view(template_name='accounts/my_password_reset_done.html'),name='my_password_reset_done'),


*My Template*






*{% extends 'base.html' %} {% block body %}  
Password Reset Done  We've emailed you instructions for setting 
your password if an account exists with the email you entered. You should 
receive them shortly. If you don't receive an email, please make sure 
you've entered the address you registered with, and check your spam folder. 
  {% endblock %}The issueif I have -path('', 
include('django.contrib.auth.urls')),in my main URL then it is loading 
default Django template. if I removed that I'm getting the error that path 
doesn't exist and I'm trying to override the Django template with my own 
template but it is not loading.*

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ab9a3d39-02ae-48c3-928d-1d1d87f508c2%40googlegroups.com.


Re: Reverse for 'modification' with no arguments not found issue

2019-08-28 Thread James Schneider
On Wed, Aug 28, 2019, 2:00 AM Ali IMRANE  wrote:

> Thanks James for your help.
>
> Indeed, I tought about that problem but I already managed to see an number
> on an other page, as well as using that ID to read information behind my
> informations (as you can see in the third line I gave on "lire.html"). A
> number is printed. How can I know that it is an *int* and not a *string*
> use in there ?
>

In the template it won't matter whether it is an int or a string, it gets
implicitly converted to a string for the regex match anyway.



>> # Nous pourrions ici envoyer l'e-mail grâce aux données
>> # que nous venons de récupérer
>> envoi = True
>> redirect(home)
>>
>>
What is the home variable in the redirect statement above? It isn't defined
in your view. I think that will need an extra argument. What line is the
traceback actually complaining about?

-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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUugGMgB6JhMkLpYc59s7%3DFi6ES3ccvRgPk%2BtXNCX2DxA%40mail.gmail.com.


Re: For validation not working for UserCreationForm

2019-08-28 Thread 'Amitesh Sahay' via Django users
Hey Kean, 
I am already working on some Djago user authentication . Below are my codes, 
may be they would help you.
views.py
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from django.contrib import messages
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from templates.authenticate.forms import SignUpForm


def home(request):
return render(request, 'authenticate/home.html', {})


def login_user(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(request, username=username, password=password)

if user is not None:
login(request, user)
messages.success(request, 'you have loggedin success')
return redirect('home')
else:
messages.success(request, 'Error loggin in')
return redirect('login')

else:
return render(request, 'authenticate/login.html', {})


def logout_user(request):
logout(request)
messages.success(request, 'You have been logged out...')
return redirect('home')


def register_user(request):
if request.method == 'POST':
form = SignUpForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data['username']
password = form.cleaned_data['password1']
user = authenticate(request, username=username, password=password)
login(request, user)
messages.success(request, 'registration successfull')
return redirect('home')
else:
form = SignUpForm()
context = {'form': form}
return render(request, 'authenticate/register.html', context)


def edit_profile(request):
if request.method == 'POST':
form = UserChangeForm(request.POST, instance=request.user)
if form.is_valid():
form.save()
username = form.cleaned_data['username']
password = form.cleaned_data['password1']
user = authenticate(request, username=username, password=password)
login(request, user)
messages.success(request, 'registration successfull')
return redirect('home')
else:
form = UserChangeForm(instance=request.user)

context = {'form': form}
return render(request, 'authenticate/edit_profile.html', context)forms.py
from django.contrib.auth.forms import UserCreationForm
from django import forms
from django.contrib.auth.models import User


class SignUpForm(UserCreationForm):
email = forms.EmailField(widget=forms.TextInput(attrs={'class': 
'form-control', 'placeholder': 'email address'}))
first_name = forms.CharField(max_length=100, 
widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'first 
name'}))
last_name = forms.CharField(max_length=100, 
widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'last 
name'}))


class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 
'password2')


def __init__(self, *args, **kwargs):
super(SignUpForm, self).__init__(*args, **kwargs)

self.fields['username'].widget.attrs['class'] = 'form-control'
self.fields['password1'].widget.attrs['class'] = 'form-control'
self.fields['password2'].widget.attrs['class'] = 'form-control'
I have also attached the HTML pages with this email in the txt format. I hope 
that helps you. Below is the django official doc link that I am referring.
https://docs.djangoproject.com/en/2.2/topics/auth/default/#auth-web-requests



Regards,
Amitesh Sahay 

On Wednesday, 28 August, 2019, 10:24:38 pm IST, Kean  
wrote:  
 
 Hi,New to Django.
I've created a registration form which inherits from a User form.The issue is 
none of the validators are working. e.g reporting to user password miss-match, 
or any other error if user enters data incorrect to validation.The form simply 
validates with errors and redirect user to to their user page (as defined,).
Please can anyone help or advise, as I though the validators were an inherent 
part of the django forms?
forms.py
class CRegisterForm(UserCreationForm):    email = 
forms.EmailField(max_length=30, required=True)
    class Meta:        model = User        fields = ['username', 'email', 
'password1', 'password2']
views.py
def cregister(request):    if request.method == "POST":        form = 
CRegisterForm(request.POST)        if form.is_valid():            data = 
form.cleaned_data            form.save()        return redirect('cpage')    
else:        form = CRegisterForm()        return render(request, 
'cregister.html', {'form': form})
urls.py
 path('login/customer/', views.cpage, name='cpage'),

html
{% load crispy_forms_tags %} 
Customer
 {% csrf_token %}  Customer Login {{ form|crispy }}  
   Login  {% if messages %}   {% for messages in 
messages %}           {{ message }} 

Re: Rest framework

2019-08-28 Thread Soumen Khatua
Thanks for your support.I got that,now I'm trying to figure out the coding
convention.


Thank You

Regards,
Soumen




On Wed, Aug 28, 2019 at 10:32 PM Andréas Kühne 
wrote:

> All of the code is documented and there should be some readme to help you
> get started.
>
> Regards,
>
> Andréas
>
>
> Den ons 28 aug. 2019 kl 15:30 skrev Soumen Khatua <
> soumenkhatua...@gmail.com>:
>
>> Hi Andres,
>> Thank you for your suggestions,Yes the database architecture is wrong.
>> Now I'm doing the practise to all the possible way to solve this
>> problem. But how I can use this plugin to solve problem meanwhile Do you
>> have any documentation for this plugin.
>>
>> Thank You
>>
>> Regards,
>> Soumen
>>
>> On Wed, Aug 28, 2019 at 6:07 PM Andréas Kühne 
>> wrote:
>>
>>> Hi,
>>>
>>> This is possible if you have a nested serializer that allow creation. We
>>> have created a plugin for that :
>>> https://pypi.org/project/drf-nested/
>>>
>>> There are several others out there that do this also - so it's
>>> completely possible.
>>>
>>> However when looking at your code  - I think the relationship isn't
>>> correct? The way you have written your code - the image is the main object
>>> and the company is secondary to it. So when you delete the image, the
>>> company will also be deleted - and you can add several companies to the
>>> same image, and not the other way around. If that is the way you want it
>>> then it's fine. But I would have a foreign key in the image to the company.
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>>
>>> Den ons 28 aug. 2019 kl 12:37 skrev Soumen Khatua <
>>> soumenkhatua...@gmail.com>:
>>>
 Hi Folks,
  I have three models like Company,Employee and images. Images is
 foreignkey in my Company table. At the time of creating Company deatils I
 want to add image also, How I add these image in my image tables and at the
 time to get method how i can show company details along with image using
 django rest framework.

 *models.py*






















 *class Image(models.Model):company_image =
  models.ImageField(upload_to='company_image',default = 'default.jpg')
 created_at = models.DateField(auto_now_add = True)updated_at =
 models.DateField(auto_now = True)class Meta:verbose_name =
 'image'def  __str__(self):return self.company_imageclass
 Company(models.Model):cmp_image = models.ForeignKey(Image,related_name
 = 'comp_image',on_delete =
   models.CASCADE)name =
 models.CharField(max_length = 100)reg_no = models.IntegerField()ceo
 = models.CharField(max_length = 100)location =
 models.CharField(max_length = 100)active =
 models.BooleanField(default=True)created_at =
 models.DateField(auto_now_add = True)updated_at =
 models.DateField(auto_now = True)def __str__(self):return
 self.name *


 Thank You

 Regards,
 Soumen


 --
 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 view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/CAPUw6WYjj4ByDwcKWhdnwCU0039WW0frfG0qF715HqAONgi1eg%40mail.gmail.com
 
 .

>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAK4qSCc4Eoh9Hw%2BahTsyPdUhPbb_Lqx7dTJWcBA0uA4itFVKbQ%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAPUw6Wam0mbXeo9%3DbO7KK6%2BDvZ4A3SCA0NpL4TC_-0mksSoi0w%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving 

Re: Rest framework

2019-08-28 Thread Andréas Kühne
All of the code is documented and there should be some readme to help you
get started.

Regards,

Andréas


Den ons 28 aug. 2019 kl 15:30 skrev Soumen Khatua :

> Hi Andres,
> Thank you for your suggestions,Yes the database architecture is wrong.
> Now I'm doing the practise to all the possible way to solve this problem.
> But how I can use this plugin to solve problem meanwhile Do you have any
> documentation for this plugin.
>
> Thank You
>
> Regards,
> Soumen
>
> On Wed, Aug 28, 2019 at 6:07 PM Andréas Kühne 
> wrote:
>
>> Hi,
>>
>> This is possible if you have a nested serializer that allow creation. We
>> have created a plugin for that :
>> https://pypi.org/project/drf-nested/
>>
>> There are several others out there that do this also - so it's completely
>> possible.
>>
>> However when looking at your code  - I think the relationship isn't
>> correct? The way you have written your code - the image is the main object
>> and the company is secondary to it. So when you delete the image, the
>> company will also be deleted - and you can add several companies to the
>> same image, and not the other way around. If that is the way you want it
>> then it's fine. But I would have a foreign key in the image to the company.
>>
>> Regards,
>>
>> Andréas
>>
>>
>> Den ons 28 aug. 2019 kl 12:37 skrev Soumen Khatua <
>> soumenkhatua...@gmail.com>:
>>
>>> Hi Folks,
>>>  I have three models like Company,Employee and images. Images is
>>> foreignkey in my Company table. At the time of creating Company deatils I
>>> want to add image also, How I add these image in my image tables and at the
>>> time to get method how i can show company details along with image using
>>> django rest framework.
>>>
>>> *models.py*
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *class Image(models.Model):company_image =
>>>  models.ImageField(upload_to='company_image',default = 'default.jpg')
>>> created_at = models.DateField(auto_now_add = True)updated_at =
>>> models.DateField(auto_now = True)class Meta:verbose_name =
>>> 'image'def  __str__(self):return self.company_imageclass
>>> Company(models.Model):cmp_image = models.ForeignKey(Image,related_name
>>> = 'comp_image',on_delete =
>>>   models.CASCADE)name =
>>> models.CharField(max_length = 100)reg_no = models.IntegerField()ceo
>>> = models.CharField(max_length = 100)location =
>>> models.CharField(max_length = 100)active =
>>> models.BooleanField(default=True)created_at =
>>> models.DateField(auto_now_add = True)updated_at =
>>> models.DateField(auto_now = True)def __str__(self):return
>>> self.name *
>>>
>>>
>>> Thank You
>>>
>>> Regards,
>>> Soumen
>>>
>>>
>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAPUw6WYjj4ByDwcKWhdnwCU0039WW0frfG0qF715HqAONgi1eg%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAK4qSCc4Eoh9Hw%2BahTsyPdUhPbb_Lqx7dTJWcBA0uA4itFVKbQ%40mail.gmail.com
>> 
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPUw6Wam0mbXeo9%3DbO7KK6%2BDvZ4A3SCA0NpL4TC_-0mksSoi0w%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK4qSCfXXaoLkF7nxv2AKU9c%2B-FohcmLKZD_uSvmOPhB3MCqQg%40mail.gmail.com.


For validation not working for UserCreationForm

2019-08-28 Thread Kean
Hi,
New to Django.

I've created a registration form which inherits from a User form.
The issue is none of the validators are working. e.g reporting to user 
password miss-match, or any other error if user enters data incorrect to 
validation.
The form simply validates with errors and redirect user to to their user 
page (as defined,).

Please can anyone help or advise, as I though the validators were an 
inherent part of the django forms?

forms.py

class CRegisterForm(UserCreationForm):
email = forms.EmailField(max_length=30, required=True)

class Meta:
model = User
fields = ['username', 'email', 'password1', 'password2']

views.py

def cregister(request):
if request.method == "POST":
form = CRegisterForm(request.POST)
if form.is_valid():
data = form.cleaned_data
form.save()
return redirect('cpage')
else:
form = CRegisterForm()
return render(request, 'cregister.html', {'form': form})

urls.py

 path('login/customer/', views.cpage, name='cpage'),

html

{% load crispy_forms_tags %}



Customer






{% csrf_token %}

Customer Login
{{ form|crispy }} 
 

Login

{% if messages %}
  {% for messages in messages %}

  {{ message }}

{% endfor %}
{% endif %}



Need a customer account Customer 
register


 





Best,

K




 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a4739118-05b9-4706-b1cb-08062cc6f93d%40googlegroups.com.


Re: Channels: launching a custom co-routine from SyncConsumer

2019-08-28 Thread Dan Merillat
On 8/15/19 11:10 PM, Andrew Godwin wrote:
> SyncConsumer isn't async - it runs inside a separate synchronous thread.
> You'll need to get the event loop from the other thread and use
> call_soon_threadsafe instead!

Sorry for the delay in getting back to you, it took me a while to go
through the different layers to find the appropriate event loop.  Thank
you for the pointer, it got me headed down what I hope is the right path.

SyncConsumer is based on AsyncConsumer, with dispatch() ultimately
wrapped in SyncToAsync via DatabaseSyncToAsync.  SyncConsumer should
have a guaranteed SyncToAsync instance with threadlocal on the executor
thread, because it is running inside a SyncToAsync to begin with.  Is
that correct?

The following "works" as part of my sync consumer but I'm not positive
what the sharp edges are going to be:

 def start_coroutine(self, coroutine):
 loop = getattr(SyncToAsync.threadlocal, "main_event_loop", None)
 if not (loop and loop.is_running()):
 loop = asyncio.new_event_loop()
 asyncio.set_event_loop(loop)
 loop.call_soon_threadsafe(loop.create_task, coroutine())

Where the coroutine is anything awaitable.

The documentation at
https://channels.readthedocs.io/en/latest/topics/consumers.html goes
into the opposite scenario, using Synchronous functions such as django
ORM from an AsyncConsumer, but would really benefit from an example of
something like an idle timeout implementation for a SyncConsumer.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8bb3ac80-3b70-e8f6-697a-af5d86086612%40gmail.com.


Re: Django sockets

2019-08-28 Thread nm

Perhaps you're looking for Django Channels? 


On Tuesday, 27 August 2019 15:08:47 UTC+2, Suraj Thapa FC wrote:
>
> Anyone know making chat app using sockets in rest api
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9a45875f-a538-4489-a486-4ccdb3be71ab%40googlegroups.com.


Unsynchronized sequence

2019-08-28 Thread Ezequias Rocha
Hello everyone

I am using django rest framework and I noticed that even I changing the 
current sequence in my database (PostgreSQL) the next element in database 
(generated by django) isn't created as I expect.

Could someone tell me if you have experienced this before?

Best regards
Ezequias

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/60700f56-aed8-44f3-902a-d084b13407df%40googlegroups.com.


Re: Rest framework

2019-08-28 Thread Soumen Khatua
Hi Andres,
Thank you for your suggestions,Yes the database architecture is wrong. Now
I'm doing the practise to all the possible way to solve this problem. But
how I can use this plugin to solve problem meanwhile Do you have any
documentation for this plugin.

Thank You

Regards,
Soumen

On Wed, Aug 28, 2019 at 6:07 PM Andréas Kühne 
wrote:

> Hi,
>
> This is possible if you have a nested serializer that allow creation. We
> have created a plugin for that :
> https://pypi.org/project/drf-nested/
>
> There are several others out there that do this also - so it's completely
> possible.
>
> However when looking at your code  - I think the relationship isn't
> correct? The way you have written your code - the image is the main object
> and the company is secondary to it. So when you delete the image, the
> company will also be deleted - and you can add several companies to the
> same image, and not the other way around. If that is the way you want it
> then it's fine. But I would have a foreign key in the image to the company.
>
> Regards,
>
> Andréas
>
>
> Den ons 28 aug. 2019 kl 12:37 skrev Soumen Khatua <
> soumenkhatua...@gmail.com>:
>
>> Hi Folks,
>>  I have three models like Company,Employee and images. Images is
>> foreignkey in my Company table. At the time of creating Company deatils I
>> want to add image also, How I add these image in my image tables and at the
>> time to get method how i can show company details along with image using
>> django rest framework.
>>
>> *models.py*
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *class Image(models.Model):company_image =
>>  models.ImageField(upload_to='company_image',default = 'default.jpg')
>> created_at = models.DateField(auto_now_add = True)updated_at =
>> models.DateField(auto_now = True)class Meta:verbose_name =
>> 'image'def  __str__(self):return self.company_imageclass
>> Company(models.Model):cmp_image = models.ForeignKey(Image,related_name
>> = 'comp_image',on_delete =
>>   models.CASCADE)name =
>> models.CharField(max_length = 100)reg_no = models.IntegerField()ceo
>> = models.CharField(max_length = 100)location =
>> models.CharField(max_length = 100)active =
>> models.BooleanField(default=True)created_at =
>> models.DateField(auto_now_add = True)updated_at =
>> models.DateField(auto_now = True)def __str__(self):return
>> self.name *
>>
>>
>> Thank You
>>
>> Regards,
>> Soumen
>>
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAPUw6WYjj4ByDwcKWhdnwCU0039WW0frfG0qF715HqAONgi1eg%40mail.gmail.com
>> 
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAK4qSCc4Eoh9Hw%2BahTsyPdUhPbb_Lqx7dTJWcBA0uA4itFVKbQ%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPUw6Wam0mbXeo9%3DbO7KK6%2BDvZ4A3SCA0NpL4TC_-0mksSoi0w%40mail.gmail.com.


confusing about running some codes in django

2019-08-28 Thread Vahid Asadi
Hi . 
when i read the django docs,it suggested that running some code but it does 
not note that where to write this piece of code . the code is :

from django.contrib.auth.models import User

u = User.objects.get(username='john')

u.set_password('new password')

u.save()


i know that i can run it in django shell (manage.py shell)

but i want to write these in a file(its some confusing that every code in 
views.py should return a http response but this type of commands does not 
return any respone) 

where should i put this code ??

thanks for your attention.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b5f90e07-d69e-42e4-ad1f-2a801b3c6114%40googlegroups.com.


How to order by prefetched set values?

2019-08-28 Thread Vlasov Vitaly
For example, i have 2 models Person and Numbers( number and 
ForeignKey(Person)

In queryset i get all persons with their related numbers. And i use 
`queryset` parameter to `Prefetch` object to filter these numbers. Result 
numbers_set can contain only 1 or 0 Number object. Number's table can 
contain any numbers for concrete Person, that's why i need prefetch filter.

Here is my code:

persons = Person.objects.all().prefecth_related(Prefecth('numbers_set', 
queryset=))

My problem in ordering. I need to order `persons` by numbers_set__number. But 
ordering working by all numbers for concrete person instead of prefetched set.

I can't use any annotation function to get this number since numbers are random 
and any does not match. Only filter can be used.

So how i can order_by prefetched numbers_set with only 1 or 0 value?

Thank you.

P.S. I read this SO question: 
https://stackoverflow.com/questions/52518569/django-2-0-order-a-queryset-by-a-field-on-the-prefetch-related-attribute
answer does not work. I use to_attr='numbers' in Prefetch object and got 
exception: Cannot resolve keyword 'numbers' into field

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/89b142ab-22cc-4b46-b44a-f47559607940%40googlegroups.com.


Re: Rest framework

2019-08-28 Thread Andréas Kühne
Hi,

This is possible if you have a nested serializer that allow creation. We
have created a plugin for that :
https://pypi.org/project/drf-nested/

There are several others out there that do this also - so it's completely
possible.

However when looking at your code  - I think the relationship isn't
correct? The way you have written your code - the image is the main object
and the company is secondary to it. So when you delete the image, the
company will also be deleted - and you can add several companies to the
same image, and not the other way around. If that is the way you want it
then it's fine. But I would have a foreign key in the image to the company.

Regards,

Andréas


Den ons 28 aug. 2019 kl 12:37 skrev Soumen Khatua :

> Hi Folks,
>  I have three models like Company,Employee and images. Images is
> foreignkey in my Company table. At the time of creating Company deatils I
> want to add image also, How I add these image in my image tables and at the
> time to get method how i can show company details along with image using
> django rest framework.
>
> *models.py*
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *class Image(models.Model):company_image =
>  models.ImageField(upload_to='company_image',default = 'default.jpg')
> created_at = models.DateField(auto_now_add = True)updated_at =
> models.DateField(auto_now = True)class Meta:verbose_name =
> 'image'def  __str__(self):return self.company_imageclass
> Company(models.Model):cmp_image = models.ForeignKey(Image,related_name
> = 'comp_image',on_delete =
>   models.CASCADE)name =
> models.CharField(max_length = 100)reg_no = models.IntegerField()ceo
> = models.CharField(max_length = 100)location =
> models.CharField(max_length = 100)active =
> models.BooleanField(default=True)created_at =
> models.DateField(auto_now_add = True)updated_at =
> models.DateField(auto_now = True)def __str__(self):return
> self.name *
>
>
> Thank You
>
> Regards,
> Soumen
>
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPUw6WYjj4ByDwcKWhdnwCU0039WW0frfG0qF715HqAONgi1eg%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK4qSCc4Eoh9Hw%2BahTsyPdUhPbb_Lqx7dTJWcBA0uA4itFVKbQ%40mail.gmail.com.


Re: Django Multiple File Upload for latest versions

2019-08-28 Thread Abu Yusuf
Thanks for your valuable feedback. I will try to fix all those.

On Tue, Aug 27, 2019 at 4:46 PM Sim  wrote:

> here is my newbie opinion :
> https://github.com/Revel109/django-multiupload-lts/issues/1
>
> good luck
>
> On Tue, Aug 27, 2019 at 9:30 AM Abu Yusuf 
> wrote:
>
>> Hey there, I have checked a lot of git projects for django latest
>> versions 'multiple file upload' but couldn't find a great one.
>>
>> Here i have created a repo for this:
>> https://github.com/Revel109/django-multiupload-lts
>>
>> Please check this out and create issues if you have any :)
>>
>> This project is live here: https://django-multiup-lts.herokuapp.com/
>>
>> Thanks.
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/02aedca4-955f-400d-8226-ba4eee1d560b%40googlegroups.com
>> 
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJenkLBLcWc1PyJt2tBR-eUwjHMdQw2sK_OrFZ2ywcmBk-dbrw%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACNsr286uT7JeDnVDUC8W4a7wfhHYotmENTNQJWLhE1Bb5Woww%40mail.gmail.com.


Re: Please help me to resolve this issue .............................[WinError 10061] No connection could be made because the target machine actively refused it

2019-08-28 Thread Kasper Laudrup

Hi Wagas,

This can only be a guess, since you haven't provided much relevant
information, but this exception:

> *Exception Type: ConnectionRefusedError at /accounts/register/*
> *Exception Value: [WinError 10061] No connection could be made because
> the target machine actively refused it*

is being thrown somewhere around here:


*
*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\smtplib.py" in __init__*

*  251.             (code, msg) = self.connect(host, port)*
*


I assume you are trying to send an email and haven't configured your 
SMTP server correctly?


Fix that in your settings.

Kind regards,

Kasper Laudrup

--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/40cac4ab-21ce-c6e3-359e-588f34ed08e3%40stacktrace.dk.


Re: i need a project developed in django +mysql database and front end in bootstrap-4

2019-08-28 Thread Desh Deepak
Hi,  Waqas

I am Desh Deepak from New Delhi, My Qualification MCA done from IGNOU.
I am experience in Python technology like python based frameworks: Django,
flask and also knowledge about MySQL8.0.

My github id: deshxpm (https://www.github.com/deshxpm)
and linkedin id: deshdeepak...@gmail.com




Best Regards
Desh Deepak
+917011101001
deshdeepak...@gmail.com

On Wed, Aug 28, 2019 at 4:08 PM Waqas Ahmad 
wrote:

> For Contact me ::: waqasahmadtarar...@gmail.com
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/df5feb98-feb3-418a-be0c-e374664bfa29%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJ0m4xgGTKLJi8NYg%2BCpYZast70X%3D4PBgbChEUgvrEuWow6apA%40mail.gmail.com.


Please help me to resolve this issue .............................[WinError 10061] No connection could be made because the target machine actively refused it

2019-08-28 Thread Waqas Ahmad
*Environment:*


*Request Method: POST*
*Request URL: http://127.0.0.1:8000/accounts/register/*

*Django Version: 2.2.4*
*Python Version: 3.7.1*
*Installed Applications:*
*['crispy_forms',*
* 'django.contrib.auth',*
* 'django.contrib.contenttypes',*
* 'django.contrib.sessions',*
* 'django.contrib.messages',*
* 'django.contrib.staticfiles',*
* 'django.contrib.sites',*
* 'registration',*
* 'django.contrib.admin',*
* 'user',*
* 'bootstrap4']*
*Installed 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']*



*Traceback:*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py"
 
in inner*
*  34. response = get_response(request)*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py"
 
in _get_response*
*  115. response = self.process_exception_by_middleware(e, 
request)*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py"
 
in _get_response*
*  113. response = wrapped_callback(request, 
*callback_args, **callback_kwargs)*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\django\views\generic\base.py"
 
in view*
*  71. return self.dispatch(request, *args, **kwargs)*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\decorators.py"
 
in _wrapper*
*  45. return bound_method(*args, **kwargs)*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\django\views\decorators\debug.py"
 
in sensitive_post_parameters_wrapper*
*  76. return view(request, *args, **kwargs)*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\registration\views.py"
 
in dispatch*
*  53. return super(RegistrationView, self).dispatch(request, 
*args, **kwargs)*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\django\views\generic\base.py"
 
in dispatch*
*  97. return handler(request, *args, **kwargs)*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\django\views\generic\edit.py"
 
in post*
*  142. return self.form_valid(form)*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\registration\views.py"
 
in form_valid*
*  56. new_user = self.register(form)*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\registration\backends\default\views.py"
 
in register*
*  100. request=self.request,*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\registration\models.py"
 
in create_inactive_user*
*  193. lambda: 
registration_profile.send_activation_email(*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\transaction.py"
 
in __exit__*
*  284. connection.set_autocommit(True)*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\base\base.py"
 
in set_autocommit*
*  410. self.run_and_clear_commit_hooks()*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\base\base.py"
 
in run_and_clear_commit_hooks*
*  636. func()*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\registration\models.py"
 
in *
*  194. site, request)*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\registration\models.py"
 
in send_activation_email*
*  451. email_message.send()*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\mail\message.py"
 
in send*
*  291. return 
self.get_connection(fail_silently).send_messages([self])*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\mail\backends\smtp.py"
 
in send_messages*
*  103. new_conn_created = self.open()*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\mail\backends\smtp.py"
 
in open*
*  63. self.connection = self.connection_class(self.host, 
self.port, **connection_params)*

*File "C:\Users\Waqas 
Ahmad\AppData\Local\Programs\Python\Python37\lib\smtplib.py" in __init__*
*  251. (code, msg) = self.connect(host, port)*

*File 

i need a project developed in django +mysql database and front end in bootstrap-4

2019-08-28 Thread Waqas Ahmad
For Contact me ::: waqasahmadtarar...@gmail.com

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/df5feb98-feb3-418a-be0c-e374664bfa29%40googlegroups.com.


Rest framework

2019-08-28 Thread Soumen Khatua
Hi Folks,
 I have three models like Company,Employee and images. Images is foreignkey
in my Company table. At the time of creating Company deatils I want to add
image also, How I add these image in my image tables and at the time to get
method how i can show company details along with image using django rest
framework.

*models.py*






















*class Image(models.Model):company_image =
 models.ImageField(upload_to='company_image',default = 'default.jpg')
created_at = models.DateField(auto_now_add = True)updated_at =
models.DateField(auto_now = True)class Meta:verbose_name =
'image'def  __str__(self):return self.company_imageclass
Company(models.Model):cmp_image = models.ForeignKey(Image,related_name
= 'comp_image',on_delete =
  models.CASCADE)name =
models.CharField(max_length = 100)reg_no = models.IntegerField()ceo
= models.CharField(max_length = 100)location =
models.CharField(max_length = 100)active =
models.BooleanField(default=True)created_at =
models.DateField(auto_now_add = True)updated_at =
models.DateField(auto_now = True)def __str__(self):return
self.name *


Thank You

Regards,
Soumen

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPUw6WYjj4ByDwcKWhdnwCU0039WW0frfG0qF715HqAONgi1eg%40mail.gmail.com.


Re: Reverse for 'modification' with no arguments not found issue

2019-08-28 Thread Ali IMRANE
Thanks James for your help.

Indeed, I tought about that problem but I already managed to see an number 
on an other page, as well as using that ID to read information behind my 
informations (as you can see in the third line I gave on "lire.html"). A 
number is printed. How can I know that it is an *int* and not a *string* 
use in there ?

Le jeudi 22 août 2019 18:27:48 UTC+2, Ali IMRANE a écrit :
>
> Hello everyone,
>
> I know I may ask this question for another time for some of you but after 
> an hour of research, I'm still stuck with this issue of "No Reverse Match".
>
> Here is my problem :
>
>- First, I using forms to put information in my DB (tickets) ;
>- I want to be able to edit those informations (check if a ticket has 
>been handled) ;
>- When I'm trying to call again my form to edit my information, even 
>if I give a specific ID, no way to reach it.
>
>
> lire.html
> ...
> {{ req.name }}
> Soumis par moi le {{ req.fromd|date:"DATE_FORMAT" }}
>   ID : {{ req.id }}
>   Type de test : {{ req.typeOfTest }}
>   Nom : {{ req.name }}
>   Date de la requête : {{ req.fromd }}
>   Périmètre : {{ req.perimetre }}
>   Owner : {{ req.owner }}
> Indice de compromission :{{ req.iocs|linebreaks 
> }}
>   Message à l'utilisateur :{{ 
> req.messageToUser|linebreaks }}
>   BAL Folder :{{ req.balFolder|linebreaks }}
>   Note :{{ req.note|linebreaks }}
>   Requête finie : {{ req.handled|linebreaks }}
>   
>type="button">Editer larequête
> ...
>
> views.py
> def view_modif(request, id):
> # Construit le formulaire, soit avec les données postées,
> # soit vide si l'user accède pour la première fois à la page.
> req = get_object_or_404(Requete, id=id)
> form_m = RequeteFormEdit(instance=req)
> # Verif que les données envoyées sont valides.
> # Cette méthode renvoie False s'il n'y a pas de
> # donnée dans le form ou qu'il contient des erreurs.
> if form_m.is_valid():
> # Ici, on traite les données du form
> form_m.typeOfTest = form_m.cleaned_data['typeOfTest']
> form_m.name = form_m.cleaned_data['name']
> form_m.tod = timezone.now
> form_m.perimetre = form_m.cleaned_data['perimetre']
> form_m.owner = form_m.cleaned_data['owner']
> form_m.iocs = form_m.cleaned_data['iocs']
> form_m.messageToUser = form_m.cleaned_data['messageToUser']
> form_m.balFolder = form_m.cleaned_data['balFolder']
> # form_m.pj = form_m.cleaned_data['pj']
> form_m.handler = form_m.cleaned_data['handler']
> form_m.note = form_m.cleaned_data['handled']
> form_m.handled = form_m.cleaned_data['note']
> 
> form_m.save()
>
> # Nous pourrions ici envoyer l'e-mail grâce aux données
> # que nous venons de récupérer
> envoi = True
> redirect(home)
>
> # Quoiqu'il arrive, on affiche la page du formulaire.
> return render(request, 'insertion/modification.html', locals())
>
> urls.py
> from django.urls import path
> from . import views
>
> urlpatterns = [
> path('', views.home, name='home'),
> path('liste', views.liste, name='liste'),
> path('requete/', views.print_req, name='voir_req'),
> path('insertion/', views.view_insert, name='insertion'),
> path('edit/', views.view_modif, name='modification'),
> path('connexion/', views.connexion, name='connexion'),
> path('deconnexion/', views.deconnexion, name='deconnexion')
> ]
>
> error :
> NoReverseMatch at /edit/1
>
> Reverse for 'modification' with no arguments not found. 1 pattern(s) tried: 
> ['edit/(?P[0-9]+)$']
>
> Request Method: GET
> Request URL: http://127.0.0.1:8000/edit/1
> Django Version: 2.0
> Exception Type: NoReverseMatch
> Exception Value: 
>
> Reverse for 'modification' with no arguments not found. 1 pattern(s) tried: 
> ['edit/(?P[0-9]+)$']
>
> Exception Location: /usr/lib/python3.7/site-packages/django/urls/resolvers.py 
> in _reverse_with_prefix, line 632
> Python Executable: /usr/bin/python
>
>
> I'm in a hurry and hope I could have the help I need thanks to 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bf830ec3-b68d-4f56-9fb0-515586bbe900%40googlegroups.com.


Re: User Register form not validating or returning errors.

2019-08-28 Thread 'Amitesh Sahay' via Django users
May be you can try the below in-built django feature for the registration form 
creation:
from django.contrib.auth.forms import UserCreationFormdef 
register_user(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data['username']
password = form.cleaned_data['password1']
user = authenticate(request, username=username, password=password)
login(request, user)
messages.success(request, 'registration successfull')
return redirect('home')
else:
form = UserCreationForm()
context = {'form': form}
return render(request, 'authenticate/register.html', context)register.html
{% extends 'authenticate/base.html' %}
{% block content %}
Registration


{%  csrf_token %}
{% if form.errors %}
Your form has errors, please fix
{%  endif %}

{{ form }}


{% endblock %}I think this should work like charm


Regards,
Amitesh Sahay 

On Wednesday, 28 August, 2019, 11:52:58 am IST, Tosin Ayoola 
 wrote:  
 
 You  didn't close the form tag that why you getting this error 
On Aug 27, 2019 21:41, "K. KOFFI"  wrote:

please put « > » before the csrf tag

Le 27 août 2019 à 16:30 +0100, Kean , a écrit :

Hi Ajeet, thanks for code, however after i press submit i get the

Forbidden (403)
CSRF verification failed. Request aborted.
Help
Reason given for failure:CSRF token missing or incorrect.
In general, this can occur when there is a genuine Cross Site Request 
Forgery, or when Django's CSRF mechanism has not been used correctly. For POST 
forms, you need to ensure:   
   - Your browser is accepting cookies.
   - The view function passes a request to the template's render method.
   - In the template, there is a {% csrf_token %} template tag inside each POST 
form that targets an internal URL.
   - If you are not using CsrfViewMiddleware, then you must use csrf_protect on 
any views that use the csrf_token template tag, as well as those that accept 
the POST data.
   - The form has a valid CSRF token. After logging in in another browser tab 
or hitting the back button after a login, you may need to reload the page with 
the form, because the token is rotated after a login.
You're seeing the help section of this page because you have DEBUG = True in 
your Django settings file. Change that to False, and only the initial error 
message will be displayed.You can customize this page using the 
CSRF_FAILURE_VIEW setting.
my template is referencing csrf_token
template.html
 Customer  "Customer 
register" {% 
csrf_token %} {{ form.as_p }} 


Am i doing something wrong?
Best,K
On 25 Aug 2019, at 08:57, Ajeet Kumar Gupt  wrote:

Hi, 
Please use the below code.

views.py__
def user_register(request):
# if this is a POST request we need to process the form data
template = 'mymodule/register.html'
   # template = 'index.html'
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = RegisterForm(request.POST)
# check whether it's valid:
if form.is_valid():
if User.objects.filter(username= form.cleaned_data['username']) 
.exists():
return render(request, template, {
'form': form,
'error_message': 'Username already exists.'
})
elif User.objects.filter(email= form.cleaned_data['email']). 
exists():
return render(request, template, {
'form': form,
'error_message': 'Email already exists.'
})
elif form.cleaned_data['password'] != form.cleaned_data['password_ 
repeat']:
return render(request, template, {
'form': form,
'error_message': 'Passwords do not match.'
})
else:
# Create the user:
user = User.objects.create_user(
form.cleaned_data['username'],
form.cleaned_data['email'],
form.cleaned_data['password']
)
user.first_name = form.cleaned_data['first_name' ]
user.last_name = form.cleaned_data['last_name']
user.phone_number = form.cleaned_data['phone_ number']
user.save()
return redirect('/login/')
# Login the user
#login(request, user)
#def user_login(request):
# redirect to accounts page:
#return render(request, '/login.html')
   # return HttpResponseRedirect(return, '/login.html')
   # No post data availabe, let's just show the page.
else:
form = RegisterForm()
return render(request, template, {'form': form})
On 

Re: User Register form not validating or returning errors.

2019-08-28 Thread Tosin Ayoola
You  didn't close the form tag that why you getting this error

On Aug 27, 2019 21:41, "K. KOFFI"  wrote:

> please put « > » before the csrf tag
>
>
> Le 27 août 2019 à 16:30 +0100, Kean , a écrit :
>
> Hi Ajeet, thanks for code,
> however after i press submit i get the
>
> Forbidden (403)
> CSRF verification failed. Request aborted.
> Help
> Reason given for failure:
>
> CSRF token missing or incorrect.
>
>
> In general, this can occur when there is a genuine Cross Site Request
> Forgery, or when Django's CSRF mechanism
>  has not been used
> correctly. For POST forms, you need to ensure:
>
>- Your browser is accepting cookies.
>- The view function passes a request to the template's render
>
> 
> method.
>- In the template, there is a {% csrf_token %} template tag inside
>each POST form that targets an internal URL.
>- If you are not using CsrfViewMiddleware, then you must use
>csrf_protect on any views that use the csrf_token template tag, as
>well as those that accept the POST data.
>- The form has a valid CSRF token. After logging in in another browser
>tab or hitting the back button after a login, you may need to reload the
>page with the form, because the token is rotated after a login.
>
> You're seeing the help section of this page because you have DEBUG = True in
> your Django settings file. Change that to False, and only the initial
> error message will be displayed.
> You can customize this page using the CSRF_FAILURE_VIEW setting.
>
> my template is referencing csrf_token
>
> template.html
>
> 
> 
> 
> Customer
> 
> 
>  "Customer register" 
> 
> 
> 
> {% csrf_token %}
> {{ form.as_p }}
> 
> 
> 
> 
> 
> 
>
>
> Am i doing something wrong?
>
> Best,
> K
>
> On 25 Aug 2019, at 08:57, Ajeet Kumar Gupt 
> wrote:
>
> Hi,
>
> Please use the below code.
>
> views.py
> __
>
> def user_register(request):
> # if this is a POST request we need to process the form data
> template = 'mymodule/register.html'
># template = 'index.html'
> if request.method == 'POST':
> # create a form instance and populate it with data from the request:
> form = RegisterForm(request.POST)
> # check whether it's valid:
> if form.is_valid():
> if 
> User.objects.filter(username=form.cleaned_data['username']).exists():
> return render(request, template, {
> 'form': form,
> 'error_message': 'Username already exists.'
> })
> elif 
> User.objects.filter(email=form.cleaned_data['email']).exists():
> return render(request, template, {
> 'form': form,
> 'error_message': 'Email already exists.'
> })
> elif form.cleaned_data['password'] != 
> form.cleaned_data['password_repeat']:
> return render(request, template, {
> 'form': form,
> 'error_message': 'Passwords do not match.'
> })
> else:
> # Create the user:
> user = User.objects.create_user(
> form.cleaned_data['username'],
> form.cleaned_data['email'],
> form.cleaned_data['password']
> )
> user.first_name = form.cleaned_data['first_name']
> user.last_name = form.cleaned_data['last_name']
> user.phone_number = form.cleaned_data['phone_number']
> user.save()
> return redirect('/login/')
> # Login the user
> #login(request, user)
> #def user_login(request):
> # redirect to accounts page:
> #return render(request, '/login.html')
># return HttpResponseRedirect(return, '/login.html')
># No post data availabe, let's just show the page.
> else:
> form = RegisterForm()
> return render(request, template, {'form': form})
>
>
> On Sat, Aug 24, 2019 at 8:34 PM Kean  wrote:
>
>> Hi,
>>
>> New to Django.
>> I've created a user registration form, the issue is it does not run
>> validations or report errors with the data entered. It simply routes to the
>> redirect url.
>> Please can I ensure the user sees the correct error in a post case
>> scenari for both a django form, and customsied django form.
>>
>> forms.py
>>
>> class UserRegisterForm(UserCreationForm):
>> email = forms.EmailField()
>>
>> class Meta:
>> model = User
>> fields = 'username', 'email', 'password1', 'password2'
>>
>> Views.py
>>
>> def register(request):
>> if request.method == 'POST':
>> form = UserRegisterForm(request.POST)
>> if form.is_valid():
>>  

Re: views and manager files according to MVT design pattern

2019-08-28 Thread Tosin Ayoola
Instead of splitting your view,  why not create a new app that way the
project will b manageable

On Aug 27, 2019 23:45, "Mike Dewhirst"  wrote:

> On 28/08/2019 4:01 am, Alejandro Cuara wrote:
>
>> Hi,
>> I would like to know if does make sense to split my views.py file into
>> multiple view files
>> trying to have a project better organized and the same for my manager.py
>> file because i noticed that
>> they have grown a lot, from my perspective it make sense to be align
>> better with the MVT design pattern
>> but I would like to know the recommendation from the official
>> documentation or the experts in this matter.
>>
>>
> I'm no expert but I have views in a single file in some apps and in a
> views directory and multiple files in other apps. This happened gradually
> for me as the views.py file grew.
>
> Nowadays, I move to multiple files earlier than before because it suits my
> brain better. And I don't use an IDE but prefer a plain text editor.
>
> It is totally your call in your circumstances.
>
>
> Thanks in advance.
>> --
>> 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 > django-users+unsubscr...@googlegroups.com>.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/ec8fb034-dd09-4de2-a61d-29563a671f55%40googlegroups.com
>> > 9-4de2-a61d-29563a671f55%40googlegroups.com?utm_medium=email
>> _source=footer>.
>>
>
> --
> 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 view this discussion on the web visit https://groups.google.com/d/ms
> gid/django-users/ed16b7fa-fba1-db43-04c6-7e8bda6fdeaf%40dewhirst.com.au.
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHLKn70dCfXHxBv0s4nbQDPTxpNQd4bhwDSB-bZrj1e0ZVehsg%40mail.gmail.com.