Re: Django template

2019-02-08 Thread Mikko Meronen
Hi,

I haven't used any other framework, so maybe someone else can better answer
that. But using my logic I think that if I want to change framework, I just
have to know how to connect again my database to my html, which is just to
learn the new framework logic I guess. But as I said, hopefully someone
wiser can answer to this :p

-Mikko

la 9. helmik. 2019 klo 8.48 Tom Zhang (computerset...@gmail.com) kirjoitti:

> Thanks. I know how to do this according to Django way. But if you use
> Django's way to transfer data, it makes it difficult to move to other
> frameworks, right? What do you think?
>
> On Saturday, February 9, 2019 at 1:42:19 AM UTC-5, Mikko wrote:
>>
>> Hi,
>>
>> You can connect your backend to frontend using views.py file. In views.py
>> you can get and sort your data from SQL and send it to your html.
>>
>> You probably should do tutorial or watch youtube videos (as I did since I
>> get bored in reading very fast) to learn more. CodingEntrepreneur has done
>> quite up to date videos, though you might need to check some point from
>> tutorial sheets as well.
>> Here is a link to backend-frontend video, but better to see the series
>> from the beginning when you are new:
>>
>>
>> https://www.youtube.com/watch?v=h05UEays2KI&list=PLEsfXFp6DpzTD1BD1aWNxS2Ep06vIkaeW&index=17
>>
>> My example from views.py, where I get and sort data from my database and
>> connect it to my webpage. In your html you need some code to get the data
>> from views.py.
>>
>> *views.py*
>>
>> from django.shortcuts import render
>> from .models import news
>>
>> def Home(request):
>> worlddata =
>> news.objects.filter(subsection__exact='World').order_by('-created')[:8]
>> args = {'worlddata': worlddata}
>> return render(request, "news/home.html", args)
>>
>> In* home.html* (bolded ones is the code you need to connect to your
>> views.py)
>>
>> *{% for news in worlddata %}*
>>  *{{ news.title }}*
>> 
>> *{% endfor %}*
>>
>> -Mikko
>>
>>
>> la 9. helmik. 2019 klo 8.15 Tom Zhang (compute...@gmail.com) kirjoitti:
>>
>>> Thanks. But if I do this way, how do I transfer data between back-end
>>> and front-end? Do I use post request?
>>>
>>>
>>> On Friday, February 8, 2019 at 8:35:28 PM UTC-5, Nitin Kalmaste wrote:

 You are correct,
 You are using HTML and JavaScript as template in django. You need to
 store static files like css/images/JavaScript in static folder and
 configure static folder in the settings file

 On Sat, Feb 9, 2019, 1:00 AM Mikko Meronen >>> wrote:

> Hi,
>
> Have to say that Im still beginner in Django and coding, but I think
> you just create you html files to your templates folder, and in the end 
> you
> are basically using just html. Django can just find your html file from
> templates folder.
>
> Im just learning javascript and I assume i can save my js-file to
> templates folder as well and connect it to my html.
>
> -Mikko
>
> pe 8.2.2019 klo 21.07 Tom Zhang  kirjoitti:
>
>> Hi, all,
>>
>> If I don't want to use Django template engine and I just want to use
>> regular html/javacript, how do I configure settings.py?
>> I am thinking about the portability issue. For example, if I want to
>> move away from django in the future, I hope my templates can still be 
>> used
>> in other frameworks, at least, with minimum changes.
>> My settings are:
>>
>> TEMPLATES = [
>> {
>> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
>> 'DIRS': [os.path.join(BASE_DIR, 'templates')],
>> 'APP_DIRS': True,
>> 'OPTIONS': {
>> 'context_processors': [
>> 'django.template.context_processors.debug',
>> 'django.template.context_processors.request',
>> 'django.contrib.auth.context_processors.auth',
>> 'django.contrib.messages.context_processors.messages',
>> ],
>> },
>> },
>> ]
>>
>> Thanks,
>>
>> Tom
>>
>> --
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/237d37a9-a913-430c-8861-eeedb8f6bece%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google
> Gro

Re: Django template

2019-02-08 Thread Tom Zhang
Thanks. I know how to do this according to Django way. But if you use 
Django's way to transfer data, it makes it difficult to move to other 
frameworks, right? What do you think?

On Saturday, February 9, 2019 at 1:42:19 AM UTC-5, Mikko wrote:
>
> Hi,
>
> You can connect your backend to frontend using views.py file. In views.py 
> you can get and sort your data from SQL and send it to your html. 
>
> You probably should do tutorial or watch youtube videos (as I did since I 
> get bored in reading very fast) to learn more. CodingEntrepreneur has done 
> quite up to date videos, though you might need to check some point from 
> tutorial sheets as well.
> Here is a link to backend-frontend video, but better to see the series 
> from the beginning when you are new:
>
>
> https://www.youtube.com/watch?v=h05UEays2KI&list=PLEsfXFp6DpzTD1BD1aWNxS2Ep06vIkaeW&index=17
>
> My example from views.py, where I get and sort data from my database and 
> connect it to my webpage. In your html you need some code to get the data 
> from views.py.
>
> *views.py*
>
> from django.shortcuts import render
> from .models import news 
>
> def Home(request):
> worlddata = 
> news.objects.filter(subsection__exact='World').order_by('-created')[:8]
> args = {'worlddata': worlddata}
> return render(request, "news/home.html", args)
>
> In* home.html* (bolded ones is the code you need to connect to your 
> views.py)
>
> *{% for news in worlddata %}*
>  *{{ news.title }}* 
> 
> *{% endfor %}*
>
> -Mikko
>
>
> la 9. helmik. 2019 klo 8.15 Tom Zhang (compute...@gmail.com ) 
> kirjoitti:
>
>> Thanks. But if I do this way, how do I transfer data between back-end and 
>> front-end? Do I use post request?
>>
>>
>> On Friday, February 8, 2019 at 8:35:28 PM UTC-5, Nitin Kalmaste wrote:
>>>
>>> You are correct,
>>> You are using HTML and JavaScript as template in django. You need to 
>>> store static files like css/images/JavaScript in static folder and 
>>> configure static folder in the settings file
>>>
>>> On Sat, Feb 9, 2019, 1:00 AM Mikko Meronen >>
 Hi,

 Have to say that Im still beginner in Django and coding, but I think 
 you just create you html files to your templates folder, and in the end 
 you 
 are basically using just html. Django can just find your html file from 
 templates folder.

 Im just learning javascript and I assume i can save my js-file to 
 templates folder as well and connect it to my html.

 -Mikko

 pe 8.2.2019 klo 21.07 Tom Zhang  kirjoitti:

> Hi, all,
>
> If I don't want to use Django template engine and I just want to use 
> regular html/javacript, how do I configure settings.py?
> I am thinking about the portability issue. For example, if I want to 
> move away from django in the future, I hope my templates can still be 
> used 
> in other frameworks, at least, with minimum changes.
> My settings are:
>
> TEMPLATES = [
> {
> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
> 'DIRS': [os.path.join(BASE_DIR, 'templates')],
> 'APP_DIRS': True,
> 'OPTIONS': {
> 'context_processors': [
> 'django.template.context_processors.debug',
> 'django.template.context_processors.request',
> 'django.contrib.auth.context_processors.auth',
> 'django.contrib.messages.context_processors.messages',
> ],
> },
> },
> ]
>
> Thanks,
>
> Tom
>
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/237d37a9-a913-430c-8861-eeedb8f6bece%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...@googlegroups.com.
 To post to this group, send email to django...@googlegroups.com.
 Visit this group at https://groups.google.com/group/django-users.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/CAGD0jjJju_32dqxzuz56z1EUqPnGirQFMFgn0RPOP_qWEGznPA%40mail.gmail.com
  
 

Re: Django template

2019-02-08 Thread Mikko Meronen
Hi,

You can connect your backend to frontend using views.py file. In views.py
you can get and sort your data from SQL and send it to your html.

You probably should do tutorial or watch youtube videos (as I did since I
get bored in reading very fast) to learn more. CodingEntrepreneur has done
quite up to date videos, though you might need to check some point from
tutorial sheets as well.
Here is a link to backend-frontend video, but better to see the series from
the beginning when you are new:

https://www.youtube.com/watch?v=h05UEays2KI&list=PLEsfXFp6DpzTD1BD1aWNxS2Ep06vIkaeW&index=17

My example from views.py, where I get and sort data from my database and
connect it to my webpage. In your html you need some code to get the data
from views.py.

*views.py*

from django.shortcuts import render
from .models import news

def Home(request):
worlddata =
news.objects.filter(subsection__exact='World').order_by('-created')[:8]
args = {'worlddata': worlddata}
return render(request, "news/home.html", args)

In* home.html* (bolded ones is the code you need to connect to your
views.py)

*{% for news in worlddata %}*
 *{{ news.title }}* 
*{% endfor %}*

-Mikko


la 9. helmik. 2019 klo 8.15 Tom Zhang (computerset...@gmail.com) kirjoitti:

> Thanks. But if I do this way, how do I transfer data between back-end and
> front-end? Do I use post request?
>
>
> On Friday, February 8, 2019 at 8:35:28 PM UTC-5, Nitin Kalmaste wrote:
>>
>> You are correct,
>> You are using HTML and JavaScript as template in django. You need to
>> store static files like css/images/JavaScript in static folder and
>> configure static folder in the settings file
>>
>> On Sat, Feb 9, 2019, 1:00 AM Mikko Meronen >
>>> Hi,
>>>
>>> Have to say that Im still beginner in Django and coding, but I think you
>>> just create you html files to your templates folder, and in the end you are
>>> basically using just html. Django can just find your html file from
>>> templates folder.
>>>
>>> Im just learning javascript and I assume i can save my js-file to
>>> templates folder as well and connect it to my html.
>>>
>>> -Mikko
>>>
>>> pe 8.2.2019 klo 21.07 Tom Zhang  kirjoitti:
>>>
 Hi, all,

 If I don't want to use Django template engine and I just want to use
 regular html/javacript, how do I configure settings.py?
 I am thinking about the portability issue. For example, if I want to
 move away from django in the future, I hope my templates can still be used
 in other frameworks, at least, with minimum changes.
 My settings are:

 TEMPLATES = [
 {
 'BACKEND': 'django.template.backends.django.DjangoTemplates',
 'DIRS': [os.path.join(BASE_DIR, 'templates')],
 'APP_DIRS': True,
 'OPTIONS': {
 'context_processors': [
 'django.template.context_processors.debug',
 'django.template.context_processors.request',
 'django.contrib.auth.context_processors.auth',
 'django.contrib.messages.context_processors.messages',
 ],
 },
 },
 ]

 Thanks,

 Tom

 --
 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 https://groups.google.com/group/django-users.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/237d37a9-a913-430c-8861-eeedb8f6bece%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...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAGD0jjJju_32dqxzuz56z1EUqPnGirQFMFgn0RPOP_qWEGznPA%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 emai

Re: Problems with CRUD, in update

2019-02-08 Thread Perchouli
Hi Ciuni,

Maybe your url already is path('updateTabacchi/', I think
question is {{ form }}.
{{ form }} is to render fields without id. Add the  if you want to
get the id from request.POST:


{% csrf_token %}



{{ form}}



On Fri, Feb 8, 2019 at 4:30 PM Giuseppe Ciuni 
wrote:

> Hi guys I'm learning django and I am doing some tests with CRUD using
> crispy forms: I created a model and I can create and read data without any
> problem.
> I have problem in update. I get this error:
>
> postalgps.models.Tabacchino.DoesNotExist: Tabacchino matching query does
> not exist
>
>
>
>
>
> *In model I have:*
>
>
> class Tabacchino(models.Model):
> nome = models.CharField(max_length=200)
> cognome = models.CharField(max_length=200)
> indirizzo = models.CharField(max_length=200)
> telefono = models.CharField(max_length=30)
> email= models.CharField(max_length=200)
> nome_tabacchi = models.CharField(max_length=200)
> attivo = models.BooleanField(blank=True)  #esiste anche l'opzione 
> null=True
> pub_date = models.DateTimeField(auto_now_add=True)
>
>
>
>
> *In views.py:*
>
>
> def updateTabacchi(request):
> query = request.POST.get('tabacchi_id')
> tabacchi = Tabacchino.objects.get(id=query)
> form = TabacchinoForm(instance=tabacchi)
> if form.is_valid():
> form.save()
> return redirect('dashboardPage')
> return render(request, 'tabacchino/admin/update_tabacchi_admin.html', 
> {'form': form, 'tabacchi': tabacchi })
>
>
>
>
> *In urls.py: *
>
>
> urlpatterns = [
> 
> path('updateTabacchi/', views.updateTabacchi, name='updateTabacchiPage'),
>
> 
>
>
>
>
> *in forms.py*
>
>
> class TabacchinoForm(forms.ModelForm):
> nome = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 
> 'xxx'}))
> cognome = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 
> 'xxx'}))
> indirizzo = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 
> 'xxx'}))
> telefono = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 
> 'xxx'}))
> email = forms.EmailField(widget=forms.TextInput(attrs={'placeholder': 
> 'xxx'}))
> nome_tabacchi = 
> forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'xxx'}))
> attivo = forms.BooleanField(required=False)
> #pub_date = forms.DateTimeField(auto_now_add=True)
>
> class Meta:
> model = Tabacchino
> #fields = "__all__"
> fields = ['nome', 'cognome', 'indirizzo', 'telefono', 'email', 
> 'nome_tabacchi', 'attivo']
>
>
>
>
>
> *In the template:*
>
>
> 
> {% csrf_token %}
> {{ form}}
>
> 
>
>
>   submit 
>
>
> 
>
>
>
>
>
>
>
>
> When I do submit from template I get:
>
>
> postalgps.models.Tabacchino.DoesNotExist: Tabacchino matching query does not 
> exist.
>
> where is the mistake?
>
> 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.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7278be12-9dc9-496f-b9d6-63f79fa4873d%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN%2BSpDJVYTW4HDZ_JiuU9D_ih_afHcoM8R6js%2Bf4O4DxusgzOg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django template

2019-02-08 Thread Tom Zhang
Thanks. But if I do this way, how do I transfer data between back-end and 
front-end? Do I use post request?


On Friday, February 8, 2019 at 8:35:28 PM UTC-5, Nitin Kalmaste wrote:
>
> You are correct,
> You are using HTML and JavaScript as template in django. You need to store 
> static files like css/images/JavaScript in static folder and configure 
> static folder in the settings file
>
> On Sat, Feb 9, 2019, 1:00 AM Mikko Meronen   wrote:
>
>> Hi,
>>
>> Have to say that Im still beginner in Django and coding, but I think you 
>> just create you html files to your templates folder, and in the end you are 
>> basically using just html. Django can just find your html file from 
>> templates folder.
>>
>> Im just learning javascript and I assume i can save my js-file to 
>> templates folder as well and connect it to my html.
>>
>> -Mikko
>>
>> pe 8.2.2019 klo 21.07 Tom Zhang > 
>> kirjoitti:
>>
>>> Hi, all,
>>>
>>> If I don't want to use Django template engine and I just want to use 
>>> regular html/javacript, how do I configure settings.py?
>>> I am thinking about the portability issue. For example, if I want to 
>>> move away from django in the future, I hope my templates can still be used 
>>> in other frameworks, at least, with minimum changes.
>>> My settings are:
>>>
>>> TEMPLATES = [
>>> {
>>> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
>>> 'DIRS': [os.path.join(BASE_DIR, 'templates')],
>>> 'APP_DIRS': True,
>>> 'OPTIONS': {
>>> 'context_processors': [
>>> 'django.template.context_processors.debug',
>>> 'django.template.context_processors.request',
>>> 'django.contrib.auth.context_processors.auth',
>>> 'django.contrib.messages.context_processors.messages',
>>> ],
>>> },
>>> },
>>> ]
>>>
>>> Thanks,
>>>
>>> Tom
>>>
>>> -- 
>>> 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 https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/237d37a9-a913-430c-8861-eeedb8f6bece%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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAGD0jjJju_32dqxzuz56z1EUqPnGirQFMFgn0RPOP_qWEGznPA%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/14ac6d90-7e51-45dc-9a15-7a5938a6a471%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django template

2019-02-08 Thread Nitin Kalmaste
You are correct,
You are using HTML and JavaScript as template in django. You need to store
static files like css/images/JavaScript in static folder and configure
static folder in the settings file

On Sat, Feb 9, 2019, 1:00 AM Mikko Meronen  Hi,
>
> Have to say that Im still beginner in Django and coding, but I think you
> just create you html files to your templates folder, and in the end you are
> basically using just html. Django can just find your html file from
> templates folder.
>
> Im just learning javascript and I assume i can save my js-file to
> templates folder as well and connect it to my html.
>
> -Mikko
>
> pe 8.2.2019 klo 21.07 Tom Zhang  kirjoitti:
>
>> Hi, all,
>>
>> If I don't want to use Django template engine and I just want to use
>> regular html/javacript, how do I configure settings.py?
>> I am thinking about the portability issue. For example, if I want to move
>> away from django in the future, I hope my templates can still be used in
>> other frameworks, at least, with minimum changes.
>> My settings are:
>>
>> TEMPLATES = [
>> {
>> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
>> 'DIRS': [os.path.join(BASE_DIR, 'templates')],
>> 'APP_DIRS': True,
>> 'OPTIONS': {
>> 'context_processors': [
>> 'django.template.context_processors.debug',
>> 'django.template.context_processors.request',
>> 'django.contrib.auth.context_processors.auth',
>> 'django.contrib.messages.context_processors.messages',
>> ],
>> },
>> },
>> ]
>>
>> Thanks,
>>
>> Tom
>>
>> --
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/237d37a9-a913-430c-8861-eeedb8f6bece%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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGD0jjJju_32dqxzuz56z1EUqPnGirQFMFgn0RPOP_qWEGznPA%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKroR%2B3GKOr2zkC%2B6OUjLwcyDMaSr38px0x8nYUgZGh5wRuU_g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Problems with CRUD, in update

2019-02-08 Thread Giuseppe Ciuni
Hi guys I'm learning django and I am doing some tests with CRUD using 
crispy forms: I created a model and I can create and read data without any 
problem.
I have problem in update. I get this error: 

postalgps.models.Tabacchino.DoesNotExist: Tabacchino matching query does 
not exist





*In model I have:*


class Tabacchino(models.Model):
nome = models.CharField(max_length=200)
cognome = models.CharField(max_length=200)
indirizzo = models.CharField(max_length=200)
telefono = models.CharField(max_length=30)
email= models.CharField(max_length=200)
nome_tabacchi = models.CharField(max_length=200)
attivo = models.BooleanField(blank=True)  #esiste anche l'opzione null=True
pub_date = models.DateTimeField(auto_now_add=True)




*In views.py:*


def updateTabacchi(request):
query = request.POST.get('tabacchi_id')
tabacchi = Tabacchino.objects.get(id=query)
form = TabacchinoForm(instance=tabacchi)
if form.is_valid():
form.save()
return redirect('dashboardPage')
return render(request, 'tabacchino/admin/update_tabacchi_admin.html', 
{'form': form, 'tabacchi': tabacchi })




*In urls.py: *


urlpatterns = [

path('updateTabacchi/', views.updateTabacchi, name='updateTabacchiPage'),






*in forms.py*


class TabacchinoForm(forms.ModelForm):
nome = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'xxx'}))
cognome = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 
'xxx'}))
indirizzo = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 
'xxx'}))
telefono = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 
'xxx'}))
email = forms.EmailField(widget=forms.TextInput(attrs={'placeholder': 
'xxx'}))
nome_tabacchi = 
forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'xxx'}))
attivo = forms.BooleanField(required=False)
#pub_date = forms.DateTimeField(auto_now_add=True)

class Meta:
model = Tabacchino
#fields = "__all__"
fields = ['nome', 'cognome', 'indirizzo', 'telefono', 'email', 
'nome_tabacchi', 'attivo']





*In the template:*



{% csrf_token %}
{{ form}}


   
   
  submit 
   
   









When I do submit from template I get:


postalgps.models.Tabacchino.DoesNotExist: Tabacchino matching query does not 
exist.

where is the mistake?

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.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7278be12-9dc9-496f-b9d6-63f79fa4873d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django timezone problem

2019-02-08 Thread Mikko Meronen
Hi,

But if  I get the visitor's timezone using JS and send it to Django using
AJAX and also do the changes below Alvaro suggested:

from django.utils import timezone

import pytz

# Set user's timezone
tzinfo = pytz.timezone(request.session['timezone'])
#request.session['timezone'] = 'America/Los_Angeles'
timezone.activate(tzinfo)
timezone.localtime(timezone.now()).isoformat()

# Resume default timezone (setting.py # TIME_ZONE)
timezone.deactivate()
timezone.localtime(timezone.now()).isoformat()


Do you think it should then be alright and my timezone.now() function works?

-Mikko



pe 8. helmik. 2019 klo 23.10 Josiah Jenson Nawaya (nawayajos...@gmail.com)
kirjoitti:

> Hi, i believe what the system do with your timezone.now() function call is
> ton currently get the timezone of the location where your server is
> located. So if your hosting server is in England, it gets the server
> location timezone. U will need to first find a way to get the visitors
> location and get the  timezone at that location. Hope it helps
>
> On Fri, Feb 8, 2019, 9:04 PM Alvaro Chen 
>> Set the timezone for the user via a property on the user is the best way.
>> Otherwise, JS can detect the user's time zone. Use moment.js (
>> https://momentjs.com/timezone/docs/#/using-timezones/guessing-user-timezone/)
>> or Intl (
>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
>> ).
>>
>> In my project, JS sends an AJAX request to Django with timezone when
>> anonymous users access the webpage. Save timezone in request.session.
>>
>> from django.utils import timezone
>> ​
>> import pytz
>> ​
>> # Set user's timezone
>> tzinfo = pytz.timezone(request.session['timezone']) 
>> #request.session['timezone'] = 'America/Los_Angeles'
>> timezone.activate(tzinfo)
>> timezone.localtime(timezone.now()).isoformat()
>> ​
>> # Resume default timezone (setting.py # TIME_ZONE)
>> timezone.deactivate()
>> timezone.localtime(timezone.now()).isoformat()
>>
>> Hope this helps.
>>
>> BR,
>>
>> Alvaro
>>
>> On Wednesday, February 6, 2019 at 12:25:45 PM UTC-8, Mikko wrote:
>>>
>>> Hi,
>>>
>>> Thank you for your help :)
>>>
>>> -Mikko
>>>
>>> ke 6.2.2019 klo 18.47 Andréas Kühne  kirjoitti:
>>>
 Hi Mikko,

 The best way to do this is actually to set the timezone for the user
 via a property on the user. The reason for this is that there is no way to
 actually get the timezone from the browser (at least not completely
 correctly). That being said, if you want to go down that route - try
 something like this: https://github.com/adamcharnock/django-tz-detect

 What it does is use javascript to get the timezone (which doesn't
 always return the right timezone) and then uses a middleware to set the
 timezone for the current user. That way you will get the information in the
 correct timezone for the user according to the browser (which might not be
 correct).

 Regards,

 Andréas


 Den mån 4 feb. 2019 kl 15:04 skrev Mikko Meronen >>> >:

> Hi,
>
> Thank you for your answer. I tried timezone.now without parentheses,
> but it gave me server error. I have also tried datetime, but I face the
> same issue.
>
> The issue I have:
> I want people to see what happened today in the past. So I created a
> database where is a story or stories what happened in the history on this
> day(date). My view should be able to pick a right story from the database
> based on the users timezone. If Australian visits my webpage at this
> moment, he should be able to see what happened on February 5 in the past
> (it's already February 5 there). However he sees what happened on February
> 4, because it is February 4 here (in Finland or England, not sure what
> timezone I'm using). So I want to make my view to understand the end 
> user's
> local time, so it can pick the right story from the database for the
> webpage visitor.
>
> -Mikko
>
> ma 4. helmik. 2019 klo 10.15 'Amitesh Sahay' via Django users (
> django...@googlegroups.com) kirjoitti:
>
>> Hello Mikko,
>>
>> There are basically two ways which I know . One is the timezone
>> module that you are using another is datetime module. I believe that
>> timezone module is more effective one.
>> But instead of calling timezone.now() , call timezone.now.
>>
>> Or what is the exact issue are you facing?
>>
>> Regards,
>> Amitesh Sahay
>> *91-750 797 8619*
>>
>>
>> On Monday, 4 February, 2019, 12:30:07 AM IST, Mikko Meronen <
>> mikkovil...@gmail.com> wrote:
>>
>>
>> Hi,
>>
>> Is there any easy way in Django to catch end user's local time when
>> end user access the webpage?
>>
>> I have read django documentation and tried to google solutions, but I
>> get quite confused. Below you will find my code. In short the code shoul

Re: Django timezone problem

2019-02-08 Thread Perchouli
Hi Mikko,

*t = timezone.now()*  just get UTC timezone when USE_TZ=True.
Modify as follows:

tzinfo = pytz.timezone('end user's timezone')
timezone.activate(tzinfo)
t = timezone.localtime(timezone.now())



On Fri, Feb 8, 2019 at 12:50 PM Mikko Meronen 
wrote:

> Hi Alvaro,
>
> If I do that (JS and AJAX), do you think my views.py is already correct? *T
> = timezone.now()* is important for me in order to get the right data from
> sql for the end user.
>
> *Views.py*
> from django.utils import timezone
>
> *t = timezone.now()* [this should detect end user's timezone]
> dm = t.strftime('%m-%d')
> history = history.objects.filter(monthday__exact=dm)
> historystory = random.sample(list(history), 1)
> args = {'historystory':historystory}
> return render(request, "news/home.html", args)
>
> -Mikko
>
> -Mikko
>
> pe 8.2.2019 klo 22.04 Alvaro Chen  kirjoitti:
>
>> Set the timezone for the user via a property on the user is the best way.
>> Otherwise, JS can detect the user's time zone. Use moment.js (
>> https://momentjs.com/timezone/docs/#/using-timezones/guessing-user-timezone/)
>> or Intl (
>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
>> ).
>>
>> In my project, JS sends an AJAX request to Django with timezone when
>> anonymous users access the webpage. Save timezone in request.session.
>>
>> from django.utils import timezone
>> ​
>> import pytz
>> ​
>> # Set user's timezone
>> tzinfo = pytz.timezone(request.session['timezone']) 
>> #request.session['timezone'] = 'America/Los_Angeles'
>> timezone.activate(tzinfo)
>> timezone.localtime(timezone.now()).isoformat()
>> ​
>> # Resume default timezone (setting.py # TIME_ZONE)
>> timezone.deactivate()
>> timezone.localtime(timezone.now()).isoformat()
>>
>> Hope this helps.
>>
>> BR,
>>
>> Alvaro
>>
>> On Wednesday, February 6, 2019 at 12:25:45 PM UTC-8, Mikko wrote:
>>>
>>> Hi,
>>>
>>> Thank you for your help :)
>>>
>>> -Mikko
>>>
>>> ke 6.2.2019 klo 18.47 Andréas Kühne  kirjoitti:
>>>
 Hi Mikko,

 The best way to do this is actually to set the timezone for the user
 via a property on the user. The reason for this is that there is no way to
 actually get the timezone from the browser (at least not completely
 correctly). That being said, if you want to go down that route - try
 something like this: https://github.com/adamcharnock/django-tz-detect

 What it does is use javascript to get the timezone (which doesn't
 always return the right timezone) and then uses a middleware to set the
 timezone for the current user. That way you will get the information in the
 correct timezone for the user according to the browser (which might not be
 correct).

 Regards,

 Andréas


 Den mån 4 feb. 2019 kl 15:04 skrev Mikko Meronen >>> >:

> Hi,
>
> Thank you for your answer. I tried timezone.now without parentheses,
> but it gave me server error. I have also tried datetime, but I face the
> same issue.
>
> The issue I have:
> I want people to see what happened today in the past. So I created a
> database where is a story or stories what happened in the history on this
> day(date). My view should be able to pick a right story from the database
> based on the users timezone. If Australian visits my webpage at this
> moment, he should be able to see what happened on February 5 in the past
> (it's already February 5 there). However he sees what happened on February
> 4, because it is February 4 here (in Finland or England, not sure what
> timezone I'm using). So I want to make my view to understand the end 
> user's
> local time, so it can pick the right story from the database for the
> webpage visitor.
>
> -Mikko
>
> ma 4. helmik. 2019 klo 10.15 'Amitesh Sahay' via Django users (
> django...@googlegroups.com) kirjoitti:
>
>> Hello Mikko,
>>
>> There are basically two ways which I know . One is the timezone
>> module that you are using another is datetime module. I believe that
>> timezone module is more effective one.
>> But instead of calling timezone.now() , call timezone.now.
>>
>> Or what is the exact issue are you facing?
>>
>> Regards,
>> Amitesh Sahay
>> *91-750 797 8619*
>>
>>
>> On Monday, 4 February, 2019, 12:30:07 AM IST, Mikko Meronen <
>> mikkovil...@gmail.com> wrote:
>>
>>
>> Hi,
>>
>> Is there any easy way in Django to catch end user's local time when
>> end user access the webpage?
>>
>> I have read django documentation and tried to google solutions, but I
>> get quite confused. Below you will find my code. In short the code should
>> show a story on my webpage what happened in the past on the current day.
>> However it doesn't take into account the endusers local time, and thus
>> doesn't work properly.
>>
>>

Re: Django timezone problem

2019-02-08 Thread Josiah Jenson Nawaya
Hi, i believe what the system do with your timezone.now() function call is
ton currently get the timezone of the location where your server is
located. So if your hosting server is in England, it gets the server
location timezone. U will need to first find a way to get the visitors
location and get the  timezone at that location. Hope it helps

On Fri, Feb 8, 2019, 9:04 PM Alvaro Chen  Set the timezone for the user via a property on the user is the best way.
> Otherwise, JS can detect the user's time zone. Use moment.js (
> https://momentjs.com/timezone/docs/#/using-timezones/guessing-user-timezone/)
> or Intl (
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
> ).
>
> In my project, JS sends an AJAX request to Django with timezone when
> anonymous users access the webpage. Save timezone in request.session.
>
> from django.utils import timezone
> ​
> import pytz
> ​
> # Set user's timezone
> tzinfo = pytz.timezone(request.session['timezone']) 
> #request.session['timezone'] = 'America/Los_Angeles'
> timezone.activate(tzinfo)
> timezone.localtime(timezone.now()).isoformat()
> ​
> # Resume default timezone (setting.py # TIME_ZONE)
> timezone.deactivate()
> timezone.localtime(timezone.now()).isoformat()
>
> Hope this helps.
>
> BR,
>
> Alvaro
>
> On Wednesday, February 6, 2019 at 12:25:45 PM UTC-8, Mikko wrote:
>>
>> Hi,
>>
>> Thank you for your help :)
>>
>> -Mikko
>>
>> ke 6.2.2019 klo 18.47 Andréas Kühne  kirjoitti:
>>
>>> Hi Mikko,
>>>
>>> The best way to do this is actually to set the timezone for the user via
>>> a property on the user. The reason for this is that there is no way to
>>> actually get the timezone from the browser (at least not completely
>>> correctly). That being said, if you want to go down that route - try
>>> something like this: https://github.com/adamcharnock/django-tz-detect
>>>
>>> What it does is use javascript to get the timezone (which doesn't always
>>> return the right timezone) and then uses a middleware to set the timezone
>>> for the current user. That way you will get the information in the correct
>>> timezone for the user according to the browser (which might not be correct).
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>>
>>> Den mån 4 feb. 2019 kl 15:04 skrev Mikko Meronen >> >:
>>>
 Hi,

 Thank you for your answer. I tried timezone.now without parentheses,
 but it gave me server error. I have also tried datetime, but I face the
 same issue.

 The issue I have:
 I want people to see what happened today in the past. So I created a
 database where is a story or stories what happened in the history on this
 day(date). My view should be able to pick a right story from the database
 based on the users timezone. If Australian visits my webpage at this
 moment, he should be able to see what happened on February 5 in the past
 (it's already February 5 there). However he sees what happened on February
 4, because it is February 4 here (in Finland or England, not sure what
 timezone I'm using). So I want to make my view to understand the end user's
 local time, so it can pick the right story from the database for the
 webpage visitor.

 -Mikko

 ma 4. helmik. 2019 klo 10.15 'Amitesh Sahay' via Django users (
 django...@googlegroups.com) kirjoitti:

> Hello Mikko,
>
> There are basically two ways which I know . One is the timezone module
> that you are using another is datetime module. I believe that timezone
> module is more effective one.
> But instead of calling timezone.now() , call timezone.now.
>
> Or what is the exact issue are you facing?
>
> Regards,
> Amitesh Sahay
> *91-750 797 8619*
>
>
> On Monday, 4 February, 2019, 12:30:07 AM IST, Mikko Meronen <
> mikkovil...@gmail.com> wrote:
>
>
> Hi,
>
> Is there any easy way in Django to catch end user's local time when
> end user access the webpage?
>
> I have read django documentation and tried to google solutions, but I
> get quite confused. Below you will find my code. In short the code should
> show a story on my webpage what happened in the past on the current day.
> However it doesn't take into account the endusers local time, and thus
> doesn't work properly.
>
>
> *Views.py*
> from django.utils import timezone
>
> t = timezone.now() *[This should somehow react to endusers local
> time]*
> dm = t.strftime('%m-%d')
> history = history.objects.filter(monthday__exact=dm)
> historystory = random.sample(list(history), 1)
> args = {'historystory':historystory}
> return render(request, "news/home.html", args)
>
> *home.html*
> [in html I have just the basic things to show the content]
>
> 
> 
> {% for x in historystory %}
>  {{ x.title }} 
>  {{ x.subtitle 

Re: Django timezone problem

2019-02-08 Thread Mikko Meronen
Hi Alvaro,

If I do that (JS and AJAX), do you think my views.py is already correct? *T
= timezone.now()* is important for me in order to get the right data from
sql for the end user.

*Views.py*
from django.utils import timezone

*t = timezone.now()* [this should detect end user's timezone]
dm = t.strftime('%m-%d')
history = history.objects.filter(monthday__exact=dm)
historystory = random.sample(list(history), 1)
args = {'historystory':historystory}
return render(request, "news/home.html", args)

-Mikko

-Mikko

pe 8.2.2019 klo 22.04 Alvaro Chen  kirjoitti:

> Set the timezone for the user via a property on the user is the best way.
> Otherwise, JS can detect the user's time zone. Use moment.js (
> https://momentjs.com/timezone/docs/#/using-timezones/guessing-user-timezone/)
> or Intl (
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
> ).
>
> In my project, JS sends an AJAX request to Django with timezone when
> anonymous users access the webpage. Save timezone in request.session.
>
> from django.utils import timezone
> ​
> import pytz
> ​
> # Set user's timezone
> tzinfo = pytz.timezone(request.session['timezone']) 
> #request.session['timezone'] = 'America/Los_Angeles'
> timezone.activate(tzinfo)
> timezone.localtime(timezone.now()).isoformat()
> ​
> # Resume default timezone (setting.py # TIME_ZONE)
> timezone.deactivate()
> timezone.localtime(timezone.now()).isoformat()
>
> Hope this helps.
>
> BR,
>
> Alvaro
>
> On Wednesday, February 6, 2019 at 12:25:45 PM UTC-8, Mikko wrote:
>>
>> Hi,
>>
>> Thank you for your help :)
>>
>> -Mikko
>>
>> ke 6.2.2019 klo 18.47 Andréas Kühne  kirjoitti:
>>
>>> Hi Mikko,
>>>
>>> The best way to do this is actually to set the timezone for the user via
>>> a property on the user. The reason for this is that there is no way to
>>> actually get the timezone from the browser (at least not completely
>>> correctly). That being said, if you want to go down that route - try
>>> something like this: https://github.com/adamcharnock/django-tz-detect
>>>
>>> What it does is use javascript to get the timezone (which doesn't always
>>> return the right timezone) and then uses a middleware to set the timezone
>>> for the current user. That way you will get the information in the correct
>>> timezone for the user according to the browser (which might not be correct).
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>>
>>> Den mån 4 feb. 2019 kl 15:04 skrev Mikko Meronen >> >:
>>>
 Hi,

 Thank you for your answer. I tried timezone.now without parentheses,
 but it gave me server error. I have also tried datetime, but I face the
 same issue.

 The issue I have:
 I want people to see what happened today in the past. So I created a
 database where is a story or stories what happened in the history on this
 day(date). My view should be able to pick a right story from the database
 based on the users timezone. If Australian visits my webpage at this
 moment, he should be able to see what happened on February 5 in the past
 (it's already February 5 there). However he sees what happened on February
 4, because it is February 4 here (in Finland or England, not sure what
 timezone I'm using). So I want to make my view to understand the end user's
 local time, so it can pick the right story from the database for the
 webpage visitor.

 -Mikko

 ma 4. helmik. 2019 klo 10.15 'Amitesh Sahay' via Django users (
 django...@googlegroups.com) kirjoitti:

> Hello Mikko,
>
> There are basically two ways which I know . One is the timezone module
> that you are using another is datetime module. I believe that timezone
> module is more effective one.
> But instead of calling timezone.now() , call timezone.now.
>
> Or what is the exact issue are you facing?
>
> Regards,
> Amitesh Sahay
> *91-750 797 8619*
>
>
> On Monday, 4 February, 2019, 12:30:07 AM IST, Mikko Meronen <
> mikkovil...@gmail.com> wrote:
>
>
> Hi,
>
> Is there any easy way in Django to catch end user's local time when
> end user access the webpage?
>
> I have read django documentation and tried to google solutions, but I
> get quite confused. Below you will find my code. In short the code should
> show a story on my webpage what happened in the past on the current day.
> However it doesn't take into account the endusers local time, and thus
> doesn't work properly.
>
>
> *Views.py*
> from django.utils import timezone
>
> t = timezone.now() *[This should somehow react to endusers local
> time]*
> dm = t.strftime('%m-%d')
> history = history.objects.filter(monthday__exact=dm)
> historystory = random.sample(list(history), 1)
> args = {'historystory':historystory}
> return render(request, "news/home.html", args)
>
> *home.html*
> [in html I have j

Re: Django timezone problem

2019-02-08 Thread Alvaro Chen


Set the timezone for the user via a property on the user is the best way. 
Otherwise, JS can detect the user's time zone. Use moment.js (
https://momentjs.com/timezone/docs/#/using-timezones/guessing-user-timezone/) 
or Intl (
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
).

In my project, JS sends an AJAX request to Django with timezone when 
anonymous users access the webpage. Save timezone in request.session. 

from django.utils import timezone
​
import pytz
​
# Set user's timezone
tzinfo = pytz.timezone(request.session['timezone']) 
#request.session['timezone'] = 'America/Los_Angeles'
timezone.activate(tzinfo)
timezone.localtime(timezone.now()).isoformat()
​
# Resume default timezone (setting.py # TIME_ZONE)
timezone.deactivate()
timezone.localtime(timezone.now()).isoformat()

Hope this helps.

BR,

Alvaro

On Wednesday, February 6, 2019 at 12:25:45 PM UTC-8, Mikko wrote:
>
> Hi,
>
> Thank you for your help :)
>
> -Mikko
>
> ke 6.2.2019 klo 18.47 Andréas Kühne > 
> kirjoitti:
>
>> Hi Mikko,
>>
>> The best way to do this is actually to set the timezone for the user via 
>> a property on the user. The reason for this is that there is no way to 
>> actually get the timezone from the browser (at least not completely 
>> correctly). That being said, if you want to go down that route - try 
>> something like this: https://github.com/adamcharnock/django-tz-detect
>>
>> What it does is use javascript to get the timezone (which doesn't always 
>> return the right timezone) and then uses a middleware to set the timezone 
>> for the current user. That way you will get the information in the correct 
>> timezone for the user according to the browser (which might not be correct).
>>
>> Regards,
>>
>> Andréas
>>
>>
>> Den mån 4 feb. 2019 kl 15:04 skrev Mikko Meronen > >:
>>
>>> Hi,
>>>
>>> Thank you for your answer. I tried timezone.now without parentheses, but 
>>> it gave me server error. I have also tried datetime, but I face the same 
>>> issue.
>>>
>>> The issue I have:
>>> I want people to see what happened today in the past. So I created a 
>>> database where is a story or stories what happened in the history on this 
>>> day(date). My view should be able to pick a right story from the database 
>>> based on the users timezone. If Australian visits my webpage at this 
>>> moment, he should be able to see what happened on February 5 in the past 
>>> (it's already February 5 there). However he sees what happened on February 
>>> 4, because it is February 4 here (in Finland or England, not sure what 
>>> timezone I'm using). So I want to make my view to understand the end user's 
>>> local time, so it can pick the right story from the database for the 
>>> webpage visitor.
>>>
>>> -Mikko
>>>
>>> ma 4. helmik. 2019 klo 10.15 'Amitesh Sahay' via Django users (
>>> django...@googlegroups.com ) kirjoitti:
>>>
 Hello Mikko,

 There are basically two ways which I know . One is the timezone module 
 that you are using another is datetime module. I believe that timezone 
 module is more effective one.
 But instead of calling timezone.now() , call timezone.now.

 Or what is the exact issue are you facing?

 Regards,
 Amitesh Sahay
 *91-750 797 8619*


 On Monday, 4 February, 2019, 12:30:07 AM IST, Mikko Meronen <
 mikkovil...@gmail.com > wrote: 


 Hi,

 Is there any easy way in Django to catch end user's local time when end 
 user access the webpage?

 I have read django documentation and tried to google solutions, but I 
 get quite confused. Below you will find my code. In short the code should 
 show a story on my webpage what happened in the past on the current day. 
 However it doesn't take into account the endusers local time, and thus 
 doesn't work properly.


 *Views.py*
 from django.utils import timezone

 t = timezone.now() *[This should somehow react to endusers local 
 time]*
 dm = t.strftime('%m-%d')
 history = history.objects.filter(monthday__exact=dm)
 historystory = random.sample(list(history), 1)
 args = {'historystory':historystory}
 return render(request, "news/home.html", args)

 *home.html*
 [in html I have just the basic things to show the content]

 
 
 {% for x in historystory %}
  {{ x.title }} 
  {{ x.subtitle }} 
  {{ x.content }} 
 {% endfor %}
 
 


 *Settings.py*
 LANGUAGE_CODE = 'en-us'
 TIME_ZONE = 'UTC'
 USE_I18N = True
 USE_L10N = True
 USE_TZ = True

 You can check my webpage (http://www.topithenewsdoggy.com/) to get 
 better understanding what I'm doing. The part is under Additional info.

 -Mikko

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group

Re: Django template

2019-02-08 Thread Tom Zhang
I will give it a try first. Thanks

On Friday, February 8, 2019 at 2:30:39 PM UTC-5, Mikko wrote:
>
> Hi,
>
> Have to say that Im still beginner in Django and coding, but I think you 
> just create you html files to your templates folder, and in the end you are 
> basically using just html. Django can just find your html file from 
> templates folder.
>
> Im just learning javascript and I assume i can save my js-file to 
> templates folder as well and connect it to my html.
>
> -Mikko
>
> pe 8.2.2019 klo 21.07 Tom Zhang > 
> kirjoitti:
>
>> Hi, all,
>>
>> If I don't want to use Django template engine and I just want to use 
>> regular html/javacript, how do I configure settings.py?
>> I am thinking about the portability issue. For example, if I want to move 
>> away from django in the future, I hope my templates can still be used in 
>> other frameworks, at least, with minimum changes.
>> My settings are:
>>
>> TEMPLATES = [
>> {
>> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
>> 'DIRS': [os.path.join(BASE_DIR, 'templates')],
>> 'APP_DIRS': True,
>> 'OPTIONS': {
>> 'context_processors': [
>> 'django.template.context_processors.debug',
>> 'django.template.context_processors.request',
>> 'django.contrib.auth.context_processors.auth',
>> 'django.contrib.messages.context_processors.messages',
>> ],
>> },
>> },
>> ]
>>
>> Thanks,
>>
>> Tom
>>
>> -- 
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/237d37a9-a913-430c-8861-eeedb8f6bece%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/493fdb29-83cd-46ea-bde9-cc27d6cecd90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django template

2019-02-08 Thread Mikko Meronen
Hi,

Have to say that Im still beginner in Django and coding, but I think you
just create you html files to your templates folder, and in the end you are
basically using just html. Django can just find your html file from
templates folder.

Im just learning javascript and I assume i can save my js-file to templates
folder as well and connect it to my html.

-Mikko

pe 8.2.2019 klo 21.07 Tom Zhang  kirjoitti:

> Hi, all,
>
> If I don't want to use Django template engine and I just want to use
> regular html/javacript, how do I configure settings.py?
> I am thinking about the portability issue. For example, if I want to move
> away from django in the future, I hope my templates can still be used in
> other frameworks, at least, with minimum changes.
> My settings are:
>
> TEMPLATES = [
> {
> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
> 'DIRS': [os.path.join(BASE_DIR, 'templates')],
> 'APP_DIRS': True,
> 'OPTIONS': {
> 'context_processors': [
> 'django.template.context_processors.debug',
> 'django.template.context_processors.request',
> 'django.contrib.auth.context_processors.auth',
> 'django.contrib.messages.context_processors.messages',
> ],
> },
> },
> ]
>
> Thanks,
>
> Tom
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/237d37a9-a913-430c-8861-eeedb8f6bece%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGD0jjJju_32dqxzuz56z1EUqPnGirQFMFgn0RPOP_qWEGznPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django template

2019-02-08 Thread Tom Zhang
Hi, all,

If I don't want to use Django template engine and I just want to use 
regular html/javacript, how do I configure settings.py?
I am thinking about the portability issue. For example, if I want to move 
away from django in the future, I hope my templates can still be used in 
other frameworks, at least, with minimum changes.
My settings are:

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

Thanks,

Tom

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/237d37a9-a913-430c-8861-eeedb8f6bece%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django template

2019-02-08 Thread Tom Zhang
Hi,

If I don't want to use any Django template and I just want to use regular 
html/javascript, how should I setup the template config in settings.py?

Right now, my settings are:

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

Thanks,

Tom

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e88d65e8-c992-4a57-ac5b-3ed5f60dab24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to display file&folder tree using Django. Help, please!

2019-02-08 Thread Mario R. Osorio
If you're just looking into just presenting trees, you might want to 
check How TO - Tree View 
(https://www.w3schools.com/howto/howto_js_treeview.asp) or Bootstrap Tree 
View 
(https://github.com/jonmiles/bootstrap-treeview, 
http://jonmiles.github.io/bootstrap-treeview/)

If you are looking for a way to create, persist and manipulate tree 
structures; you need to check django_trees 
(https://github.com/imtapps/django-trees)

HTH


On Friday, February 8, 2019 at 7:24:01 AM UTC-5, Yura wrote:
>
> Hello everyone! I really need help. I’ve got SQL table which contains 
> exhaustive files and folders information and I need to show tree of those 
> files on a website. But not only show, it’s supposed to be interactive, so 
> that a user can scroll, open folders and mark any of the items. 
> I think it might look like an example on the attached picture (or here, 
> example png link: https://yadi.sk/i/H3wzUMt_UmT3AQ ). 
> If someone can give advice how to implement this app in django that would 
> be really helpful, or maybe just any thoughts regarding it, I’d really 
> appreciate it.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6b089875-296f-4908-9582-71d4b1bcc0fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Password Policy Adherence. Cannot use the passwords used before

2019-02-08 Thread Matthew Pava
I completely support this NIST policy, James.  Unfortunately, the PCI Security 
Standards Council does not support this policy at this time.  In order for a 
company to be PCI compliant, users must change their passwords every three 
months.  PCI compliance is essential for companies to adhere to when they are 
processing credit cards.  There are ways around the requirements; companies 
could basically out-source credit card processing to other companies such as 
Stripe or Square, but they need to know what they are doing to maintain 
compliance.

https://www.pcisecuritystandards.org/documents/Payment-Data-Security-Essential-Strong-Passwords.pdf?agreement=true&time=1549638814227



From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of James Bennett
Sent: Friday, February 8, 2019 9:00 AM
To: django-users@googlegroups.com
Subject: Re: Password Policy Adherence. Cannot use the passwords used before

I'm going to suggest you step back and consider whether the policies you want 
to implement are good policies. A good, solidly-researched set of 
recommendations is NIST SP800-63B:

https://pages.nist.gov/800-63-3/sp800-63b.html

In particular, NIST suggests the following:

* Do not use a policy which automatically "expires" passwords and forces users 
to change them periodically. Only force a password change when you have 
evidence that a password has been compromised.
* Do not try to impose artificial "complexity" rules (like requiring a mix of 
uppercase/lowercase, numbers and symbols).
* When a user changes their password, compare it against lists of 
known-compromised passwords.

Forcing users to change their passwords on a set schedule just encourages them 
to choose weak passwords that are easy to remember. If you force me to change 
my password every three months, for example, here's what I'll do:

* P@ssword!2019_1
* P@ssword!2019_2
* P@ssword!2019_3
* P@ssword!2019_4

These passwords are all different from each other, and they each contain at 
least one uppercase and one lowercase letter, at least one number and at least 
one symbol. They're also terrible passwords that would probably get cracked 
within minutes, if not seconds, by any good automated cracker.
That's a year's worth of passwords, each of which is different from the last, 
each contains one
--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAL13Cg9Xi7QdCCffqROi_FjLzKimtWYBR%3DusMxf6ihf_E6%3D-9A%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7d7e9de09028498e8fca89973db6484f%40iss2.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Re: Password Policy Adherence. Cannot use the passwords used before

2019-02-08 Thread James Bennett
I'm going to suggest you step back and consider whether the policies you
want to implement are good policies. A good, solidly-researched set of
recommendations is NIST SP800-63B:

https://pages.nist.gov/800-63-3/sp800-63b.html

In particular, NIST suggests the following:

* Do not use a policy which automatically "expires" passwords and forces
users to change them periodically. Only force a password change when you
have evidence that a password has been compromised.
* Do not try to impose artificial "complexity" rules (like requiring a mix
of uppercase/lowercase, numbers and symbols).
* When a user changes their password, compare it against lists of
known-compromised passwords.

Forcing users to change their passwords on a set schedule just encourages
them to choose weak passwords that are easy to remember. If you force me to
change my password every three months, for example, here's what I'll do:

* P@ssword!2019_1
* P@ssword!2019_2
* P@ssword!2019_3
* P@ssword!2019_4

These passwords are all different from each other, and they each contain at
least one uppercase and one lowercase letter, at least one number and at
least one symbol. They're also terrible passwords that would probably get
cracked within minutes, if not seconds, by any good automated cracker.
That's a year's worth of passwords, each of which is different from the
last, each contains one

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAL13Cg9Xi7QdCCffqROi_FjLzKimtWYBR%3DusMxf6ihf_E6%3D-9A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Password Policy Adherence. Cannot use the passwords used before

2019-02-08 Thread Jason
I haven't found anything like a drop-in replacement, but this should be 
fairly simple for you to do.

when a password changes, the hash of the former password is stored in a 
different table with a reference to the user and the timestamp.  when a new 
password is entered in as a reset, you compare the last 6 passwords ordered 
by timestamp and see if any match.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/de7dc9af-4421-449f-9247-7cd441210490%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to display file&folder tree using Django. Help, please!

2019-02-08 Thread Yura
Hello everyone! I really need help. I’ve got SQL table which contains 
exhaustive files and folders information and I need to show tree of those 
files on a website. But not only show, it’s supposed to be interactive, so 
that a user can scroll, open folders and mark any of the items. 
I think it might look like an example on the attached picture (or here, 
example png link: https://yadi.sk/i/H3wzUMt_UmT3AQ ). 
If someone can give advice how to implement this app in django that would 
be really helpful, or maybe just any thoughts regarding it, I’d really 
appreciate it.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7466733b-5944-4b58-b293-b32b7566ff6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Exception happened during processing of request from ...

2019-02-08 Thread Pedram Badakhchani
I am getting similar errors, also running Django 2.15 with python 3.72, 
would be very interested if you have found a solution

On Thursday, 31 January 2019 15:52:38 UTC, Jon bae wrote:
>
> Hello,
> I'm running here *django 2.1.5* with *python 3.7.2* (installed with 
> homebrew) on a macOS (mojave).
>
> On a regular basis I get this error message:
>
> Exception happened during processing of request from ('127.0.0.1', 54882)
> Traceback (most recent call last):
>   File 
> "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py"
> , line 650, in process_request_thread
> self.finish_request(request, client_address)
>   File 
> "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py"
> , line 360, in finish_request
> self.RequestHandlerClass(request, client_address, self)
>   File 
> "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py"
> , line 720, in __init__
> self.handle()
>   File "/Users/User
> /DEV/gogs/TV-Webpage/venv/lib/python3.7/site-packages/django/core/servers/basehttp.py"
> , line 171, in handle
> self.handle_one_request()
>   File 
> "/Users/User/DEV/gogs/TV-Webpage/venv/lib/python3.7/site-packages/django/core/servers/basehttp.py"
> , line 179, in handle_one_request
> self.raw_requestline = self.rfile.readline(65537)
>   File 
> "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py"
> , line 589, in readinto
> return self._sock.recv_into(b)
> ConnectionResetError: [Errno 54] Connection reset by peer
> 
>
> It comes for example when I open the admin page, but not always.
>
>
> Have you any idea how I can fix that?
>
> Have a nice day!
>
> Jonathan
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/37d32596-5b27-47db-8178-2a45970b2c0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.