Re: path('posts/(?P[0-9]+)/$'

2018-12-02 Thread Lachlan Musicman
On Mon, 3 Dec 2018 at 11:51,  wrote:

>
>
> On Sunday, December 2, 2018 at 10:00:17 AM UTC-8, Jani Tiainen wrote:
>>
>> Hi.
>>
>> Path is a new url format which uses format of  for
>> exanple like  . If you want to use regular expressions use
>> re_path instead.
>>
>>  kirjoitti su 2. jouluk. 2018 klo 19.42:
>>
>>> When I run http://localhost:8000/posts/2
>>>
>>> Here is my .py's
>>>
>>> from django.contrib import admin
>>> from django.urls import path
>>> from posts import views
>>> from django.conf.urls.static import static
>>> from django.conf import settings
>>>
>>> urlpatterns = [
>>>   path('admin/', admin.site.urls),
>>>   path('', views.home),
>>>   path('posts/(?P[0-9]+)/$', views.post_details),
>>>
>>>   ] + static(settings.MEDIA_URL, document_root = 
>>> settings.MEDIA_ROOT)
>>>
>>>
>>>

So, to your urls.py you need to add:

from django.urls import path, re_path

And your url patterns will need to look like

re_path('posts/(?P[0-9]+)/$', views.post_details),

I've not looked for a while, but it might even need to be

re_path(r'posts/(?P[0-9]+)/$', views.post_details),

Cheers

L.




 --
"The fact that you're still saying something like 'feminism gone mad'
suggests that feminism hasn't gone mad ENOUGH yet."

Helen Zaltzman / @HelenZaltzman
https://twitter.com/HelenZaltzman/status/1065384934846545920

-- 
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/CAGBeqiPuTq_4N2dd9nBDDPfFfOo0Ra_0Q23i5k0Wjgmhe4%2B5KQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: path('posts/(?P[0-9]+)/$'

2018-12-02 Thread ehrenfeld1946
I am new to django so I am not sure I understand what you are saying. Can 
you give me a rewrite of the correct syntax of the line that is not correct?

Thank you

On Sunday, December 2, 2018 at 10:00:17 AM UTC-8, Jani Tiainen wrote:
>
> Hi.
>
> Path is a new url format which uses format of  for 
> exanple like  . If you want to use regular expressions use 
> re_path instead. 
>
> > kirjoitti su 2. jouluk. 2018 klo 
> 19.42:
>
>> When I run http://localhost:8000/posts/2
>>
>> I get the error:
>>
>>
>>   Using the URLconf defined in blog.urls,
>>   Django tried these URL patterns, in this order:
>>   
>>
>>1. admin/
>>2. 
>>3. Posts/(?P[0-9]+)/$
>>4. ^media/(?P.*)$
>> The current path, posts/2, didn't match any of these.
>>
>>
>> Here is my .py's
>>
>> from django.contrib import admin
>> from django.urls import path
>> from posts import views
>> from django.conf.urls.static import static
>> from django.conf import settings
>>
>> urlpatterns = [
>>   path('admin/', admin.site.urls),
>>   path('', views.home),
>>   path('posts/(?P[0-9]+)/$', views.post_details),
>>
>>   ] + static(settings.MEDIA_URL, document_root = 
>> settings.MEDIA_ROOT)
>>
>>
>> views.py
>>
>> from django.shortcuts import render
>> from posts.models import Post
>>
>> # Create your views here.
>> def home(request):
>> posts = Post.objects.order_by('pub_date')
>>
>> return render(request, 'posts/home.html', {'posts': posts})
>>
>> def post_details(request, post_id):
>> return render(request, "posts/posts_detail.html", {'post_id': post_id})
>>
>>
>> Any ideas why it doesn't work. I am a newbie with django
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@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/d28eac04-2edc-405e-9942-e883b1e7bff8%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/2f56611d-1510-4f94-b2a2-82aa0a700780%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Best way to structure this Django project

2018-12-02 Thread Simon Connah

Hi,

I have a bit of a problem with structuring a Django project. I have a 
UserProfile app which stores extra information about users using a 
OneToOneField to the Django auth user model.


I have a products app which has two models relating to two types of 
products and finally I have a payments app which contains all the code 
needed to integrate with the Stripe payment processor.


My problem is fairly simple. When someone buys a product I obviously 
want to take them to a payment page but if I carry on with my current 
structure that would require redirecting to a view in the payments app 
as it will contain code to work with the Stripe API but it would also 
require access to the product model(s) which would hard code a 
dependency between the payments app and the products app.


Is there anyway I can rearrange my project so I can avoid this hard 
coded dependency?


--
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/12030aa1-69ad-dc7f-c3be-72e8e2f9b50e%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to do the initial migrations with django-2.1.3 and "mysql 5.5.62-0+deb8u1 (Debian)"

2018-12-02 Thread Periklis Gkolias
Thanks Simon, I havent noticed that.

On Sun, Dec 2, 2018 at 10:57 PM Simon Charette  wrote:

> Hello there,
>
> Django 2.1 dropped support for MySQL 5.5[0] as the end of
> upstream support is December 2018.
>
> You'll have to update to a more recent version to use Django 2.1+.
>
> Cheers,
> Simon
>
> [0]
> https://docs.djangoproject.com/en/2.1/releases/2.1/#dropped-support-for-mysql-5-5
>
> Le dimanche 2 décembre 2018 15:44:22 UTC-5, Periklis Gkolias a écrit :
>>
>> Hi there,
>>
>> I am trying to bootstrap a project with mysql and django with the
>> versions described in the subject line.
>>
>> The app works fine if I just do a "runserver" and ignore the migration
>> warning but when I apply the migrations I am getting the stacktrace you can
>> see in the linked
>> 
>> file.
>>
>>
>> I have seen similar stuff in SO like this
>> 
>>  but
>> none of the solutions have worked.
>>
>> I would highly appreciate any piece of documentation to guide me further.
>> Of course, do not hesitate to contact me if you have any questions.
>>
>> Thanks,
>> Periklis
>>
> --
> 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/6fb5c24a-a420-42bf-90bc-fe5e0f35a665%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/CAE_d2biW5UULZeAdDdPPYsupV7tiE3evcxtKiC7xU1Ka3UXbvA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to do the initial migrations with django-2.1.3 and "mysql 5.5.62-0+deb8u1 (Debian)"

2018-12-02 Thread Simon Charette
Hello there,

Django 2.1 dropped support for MySQL 5.5[0] as the end of
upstream support is December 2018.

You'll have to update to a more recent version to use Django 2.1+.

Cheers,
Simon

[0] 
https://docs.djangoproject.com/en/2.1/releases/2.1/#dropped-support-for-mysql-5-5

Le dimanche 2 décembre 2018 15:44:22 UTC-5, Periklis Gkolias a écrit :
>
> Hi there,
>
> I am trying to bootstrap a project with mysql and django with the versions 
> described in the subject line.
>
> The app works fine if I just do a "runserver" and ignore the migration 
> warning but when I apply the migrations I am getting the stacktrace you can 
> see in the linked 
> 
>  
> file.
>
>
> I have seen similar stuff in SO like this 
> 
>  but 
> none of the solutions have worked.
>
> I would highly appreciate any piece of documentation to guide me further. 
> Of course, do not hesitate to contact me if you have any questions.
>
> Thanks,
> Periklis
>

-- 
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/6fb5c24a-a420-42bf-90bc-fe5e0f35a665%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Annotate giving back individual queries rather than results

2018-12-02 Thread Simon Charette
Hey there,

I just wanted to clarify that the behavior of including the Meta.ordering
fields in aggregation grouping been around for a while and Django 2.2
deprecates it to deal with the exact type of confusion you experienced here.

Best,
Simon

Le dimanche 2 décembre 2018 08:51:17 UTC-5, Coder Dude a écrit :
>
> Solved It.
> It seems as of django 2.1, we need to add another parameter order_by
>
> *Submission*.*objects*.values('user').annotate(Count('id')).order_by('user')
>
>
> *documentation 
> *
>
>
> *Thanks*
>
>
>
>
>
>
> On Sunday, December 2, 2018 at 6:44:21 PM UTC+5:30, Coder Dude wrote:
>>
>> Here are my models:
>> from django.contrib.auth.models import User as DefaultUser
>> class Submission(models.Model):
>> user = models.ForeignKey(to=DefaultUser,
>> on_delete=models.CASCADE
>> )
>> total_score = models.DecimalField()
>>
>>
>> The query that I am trying is : 
>>
>> *Submission*.*objects*.values('user').annotate(Count('id'))
>>
>>
>> I want to get the count of Submissions for each user
>>
>> But this returns me set of individual submission with count as 1
>>
>>
>> *Output:*
>>
>> {'user': 1, 'id__count': 1}
>> {'user': 1, 'id__count': 1}
>> {'user': 1, 'id__count': 1}
>> {'user': 1, 'id__count': 1}
>> {'user': 2, 'id__count': 1}
>> {'user': 2, 'id__count': 1}
>> {'user': 3, 'id__count': 1}
>>
>>
>> Whereas the output that I want is:
>>
>> {'user': 1, 'id__count': 4}
>> {'user': 2, 'id__count': 2}
>> {'user': 3, 'id__count': 1}
>>
>>
>> What am I doing wrong?
>>
>> Please help
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2ca60905-62e9-4814-9d03-74f227f0604d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Unable to do the initial migrations with django-2.1.3 and "mysql 5.5.62-0+deb8u1 (Debian)"

2018-12-02 Thread Periklis Gkolias
Hi there,

I am trying to bootstrap a project with mysql and django with the versions 
described in the subject line.

The app works fine if I just do a "runserver" and ignore the migration 
warning but when I apply the migrations I am getting the stacktrace you can 
see in the linked 

 
file.


I have seen similar stuff in SO like this 

 but 
none of the solutions have worked.

I would highly appreciate any piece of documentation to guide me further. 
Of course, do not hesitate to contact me if you have any questions.

Thanks,
Periklis

-- 
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/cfbcadb1-09e0-49c9-b88e-9e215706dd65%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: path('posts/(?P[0-9]+)/$'

2018-12-02 Thread Jani Tiainen
Hi.

Path is a new url format which uses format of  for exanple
like  . If you want to use regular expressions use re_path
instead.

 kirjoitti su 2. jouluk. 2018 klo 19.42:

> When I run http://localhost:8000/posts/2
>
> I get the error:
>
>
>   Using the URLconf defined in blog.urls,
>   Django tried these URL patterns, in this order:
>
>
>1. admin/
>2.
>3. Posts/(?P[0-9]+)/$
>4. ^media/(?P.*)$
> The current path, posts/2, didn't match any of these.
>
>
> Here is my .py's
>
> from django.contrib import admin
> from django.urls import path
> from posts import views
> from django.conf.urls.static import static
> from django.conf import settings
>
> urlpatterns = [
>   path('admin/', admin.site.urls),
>   path('', views.home),
>   path('posts/(?P[0-9]+)/$', views.post_details),
>
>   ] + static(settings.MEDIA_URL, document_root = 
> settings.MEDIA_ROOT)
>
>
> views.py
>
> from django.shortcuts import render
> from posts.models import Post
>
> # Create your views here.
> def home(request):
> posts = Post.objects.order_by('pub_date')
>
> return render(request, 'posts/home.html', {'posts': posts})
>
> def post_details(request, post_id):
> return render(request, "posts/posts_detail.html", {'post_id': post_id})
>
>
> Any ideas why it doesn't work. I am a newbie with django
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d28eac04-2edc-405e-9942-e883b1e7bff8%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/CAHn91of_f5HKn36niAVbuVjg%3DmxYeLPSHxRxBOn5kRiW9ZLD2w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


path('posts/(?P[0-9]+)/$'

2018-12-02 Thread ehrenfeld1946
When I run http://localhost:8000/posts/2

I get the error:


  Using the URLconf defined in blog.urls,
  Django tried these URL patterns, in this order:
  

   1. admin/
   2. 
   3. Posts/(?P[0-9]+)/$
   4. ^media/(?P.*)$
The current path, posts/2, didn't match any of these.


Here is my .py's

from django.contrib import admin
from django.urls import path
from posts import views
from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [
  path('admin/', admin.site.urls),
  path('', views.home),
  path('posts/(?P[0-9]+)/$', views.post_details),

  ] + static(settings.MEDIA_URL, document_root = 
settings.MEDIA_ROOT)


views.py

from django.shortcuts import render
from posts.models import Post

# Create your views here.
def home(request):
posts = Post.objects.order_by('pub_date')

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

def post_details(request, post_id):
return render(request, "posts/posts_detail.html", {'post_id': post_id})


Any ideas why it doesn't work. I am a newbie with django

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d28eac04-2edc-405e-9942-e883b1e7bff8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Annotate giving back individual queries rather than results

2018-12-02 Thread Coder Dude
Solved It.
It seems as of django 2.1, we need to add another parameter order_by

*Submission*.*objects*.values('user').annotate(Count('id')).order_by('user')


*documentation 
*


*Thanks*






On Sunday, December 2, 2018 at 6:44:21 PM UTC+5:30, Coder Dude wrote:
>
> Here are my models:
> from django.contrib.auth.models import User as DefaultUser
> class Submission(models.Model):
> user = models.ForeignKey(to=DefaultUser,
> on_delete=models.CASCADE
> )
> total_score = models.DecimalField()
>
>
> The query that I am trying is : 
>
> *Submission*.*objects*.values('user').annotate(Count('id'))
>
>
> I want to get the count of Submissions for each user
>
> But this returns me set of individual submission with count as 1
>
>
> *Output:*
>
> {'user': 1, 'id__count': 1}
> {'user': 1, 'id__count': 1}
> {'user': 1, 'id__count': 1}
> {'user': 1, 'id__count': 1}
> {'user': 2, 'id__count': 1}
> {'user': 2, 'id__count': 1}
> {'user': 3, 'id__count': 1}
>
>
> Whereas the output that I want is:
>
> {'user': 1, 'id__count': 4}
> {'user': 2, 'id__count': 2}
> {'user': 3, 'id__count': 1}
>
>
> What am I doing wrong?
>
> Please help
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/add4bede-4a98-4124-a2d9-eecfd393763a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Annotate giving back individual queries rather than results

2018-12-02 Thread Coder Dude
Here are my models:
from django.contrib.auth.models import User as DefaultUser
class Submission(models.Model):
user = models.ForeignKey(to=DefaultUser,
on_delete=models.CASCADE
)
total_score = models.DecimalField()


The query that I am trying is : 

*Submission*.*objects*.values('user').annotate(Count('id'))


I want to get the count of Submissions for each user

But this returns me set of individual submission with count as 1


*Output:*

{'user': 1, 'id__count': 1}
{'user': 1, 'id__count': 1}
{'user': 1, 'id__count': 1}
{'user': 1, 'id__count': 1}
{'user': 2, 'id__count': 1}
{'user': 2, 'id__count': 1}
{'user': 3, 'id__count': 1}


Whereas the output that I want is:

{'user': 1, 'id__count': 4}
{'user': 2, 'id__count': 2}
{'user': 3, 'id__count': 1}


What am I doing wrong?

Please help


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5066d27d-632d-4c01-98d3-2114c8043e1d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Forbidden (CSRF token missing or incorrect.)

2018-12-02 Thread Rabah Saadi
Hi guys.

Thank you for the answers. I forgot to tell you that I hit the server in 
Developement and it is http. (local)

I did put these parameters in my settings.py :

CSRF_COOKIE_SECURE = False
SESSION_COOKIE_SECURE = False

but it keeps displaying the same message :

Forbidden (CSRF token missing or incorrect.): /vehicule/
[02/Dec/2018 08:03:10] 
"pagination%5Bpage%5D=1&pagination%5Bperpage%5D=10&sort%5Bsort%5D=asc&sort%5Bfield%5D=OrderID&query=GET
 
/vehicule/ HTTP/1.1" 403 2536


but it display it just once this time after I pulled the last Django Dev 
from github, this is happening after I logged in and click on any page that 
has a CSRF it display a 403 page after I refresh the browser or reload it 
it, everythin works fine, you can click on whatever you want it will work 
fine.

so now just one time after logging in.

I'm using the built in logging django machinery (Views and URLs), not even 
my own views to manage logging.

Thank you guys.
 

Le mercredi 21 novembre 2018 05:38:19 UTC-8, Rabah Saadi a écrit :
>
> Hello,
>
> I've been using Django 2.2Dev for a while now, since April 2018, and it is 
> working just fine (I got my reasons why Django Dev). But since the last git 
> pull, it shows the CSRF token missing, on every page has a form with CSRF 
> token. 
>
> Is there something broke or ... ? since My Django-2.2Dev before the last 
> "git pull" was working just fine.
>
> PS : Donwgrade to Django 2.1.3 stable, works fine too.
>
> thank you.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/58f570ae-8912-4922-b6cd-af8839b314a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.