Re: Random 404 instead of 301 for URLs without trailing slash

2016-09-16 Thread Michal Petrucha
Hi Frederik,

On Fri, Sep 16, 2016 at 09:01:53AM -0700, Frederik Elwert wrote:
> Hello,
> 
> I am running a site that uses Django 1.8 and Django CMS 3.2. The site is 
> deployed using gunicorn and nginx. Now I noticed a strange, hard to debug 
> issue: When accessing a URL without trailing slash, I expect a redirect to 
> the correct URL with the trailing slash appended, as per the APPEND_SLASH 
> setting. This usually works, but sometimes I get a 404 instead of the 
> correct 301. I can reproduce this using curl:
> 
> $ curl -I http://khk.ceres.rub.de/en/research/focus-groups/notions
> HTTP/1.1 404 NOT FOUND
> Server: nginx/1.6.2
> Date: Fri, 16 Sep 2016 15:54:40 GMT
> Content-Type: text/html
> Connection: keep-alive
> x-xss-protection: 1; mode=block
> Content-Language: en
> x-content-type-options: nosniff
> Vary: Cookie
> X-Frame-Options: SAMEORIGIN
> Set-Cookie: django_language=en; expires=Sat, 16-Sep-2017 15:54:40 GMT; 
> Max-Age=31536000; Path=/
> 
> $ curl -I http://khk.ceres.rub.de/en/research/focus-groups/notions
> HTTP/1.1 301 MOVED PERMANENTLY
> Server: nginx/1.6.2
> Date: Fri, 16 Sep 2016 15:54:42 GMT
> Content-Type: text/html; charset=utf-8
> Connection: keep-alive
> x-xss-protection: 1; mode=block
> Content-Language: en
> x-content-type-options: nosniff
> Vary: Cookie
> Location: http://khk.ceres.rub.de/en/research/focus-groups/notions/
> X-Frame-Options: SAMEORIGIN
> Set-Cookie: django_language=en; expires=Sat, 16-Sep-2017 15:54:42 GMT; 
> Max-Age=31536000; Path=/
> 
> I am a bit clueless why this behaviour is so unpredictable. Any ideas what 
> might be going on here, or how to trace this?

APPEND_SLASH only applies to URLs that do not match any URL pattern.
It is possible that you have a catch-all urlpattern that happens to
match your URL without a trailing slash, and then raise an explicit
404 – this might happen, for instance, if you're using something like
a wiki application, or a custom handler for flatpages, included under
a particular URL prefix.

Good luck,

Michal

-- 
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/20160916163757.GY6601%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: export html to pdf

2016-09-16 Thread Michael Macdonald
Excellent article.  I played with a couple of the specific tools mentioned 
there but in my little application it wound up being more efficient and 
sufficient to format a printed page in HTML.  

On Thursday, September 15, 2016 at 6:49:18 AM UTC-7, Derek wrote:
>
> There is a useful overview of different tools here:
> https://spapas.github.io/2015/11/27/pdf-in-django/
>
>
> On Wednesday, 14 September 2016 16:46:57 UTC+2, Saeon Tao wrote:
>>
>> Hi guys,
>>
>> Does someone have a great suggestion for exporting an html div and save 
>> to pdf? i have found many options, only some of which are integrated with 
>> django.
>> In your experience, which is the best one to use for django==1.6.2 ? 
>> should i choose an integrated one? or is it possible to use jquery alone 
>> for this?
>>
>> 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/aafdb103-956f-45c6-86ba-6ea1ce2d4fac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Random 404 instead of 301 for URLs without trailing slash

2016-09-16 Thread Frederik Elwert
Hello,

I am running a site that uses Django 1.8 and Django CMS 3.2. The site is 
deployed using gunicorn and nginx. Now I noticed a strange, hard to debug 
issue: When accessing a URL without trailing slash, I expect a redirect to 
the correct URL with the trailing slash appended, as per the APPEND_SLASH 
setting. This usually works, but sometimes I get a 404 instead of the 
correct 301. I can reproduce this using curl:

$ curl -I http://khk.ceres.rub.de/en/research/focus-groups/notions
HTTP/1.1 404 NOT FOUND
Server: nginx/1.6.2
Date: Fri, 16 Sep 2016 15:54:40 GMT
Content-Type: text/html
Connection: keep-alive
x-xss-protection: 1; mode=block
Content-Language: en
x-content-type-options: nosniff
Vary: Cookie
X-Frame-Options: SAMEORIGIN
Set-Cookie: django_language=en; expires=Sat, 16-Sep-2017 15:54:40 GMT; 
Max-Age=31536000; Path=/

$ curl -I http://khk.ceres.rub.de/en/research/focus-groups/notions
HTTP/1.1 301 MOVED PERMANENTLY
Server: nginx/1.6.2
Date: Fri, 16 Sep 2016 15:54:42 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
x-xss-protection: 1; mode=block
Content-Language: en
x-content-type-options: nosniff
Vary: Cookie
Location: http://khk.ceres.rub.de/en/research/focus-groups/notions/
X-Frame-Options: SAMEORIGIN
Set-Cookie: django_language=en; expires=Sat, 16-Sep-2017 15:54:42 GMT; 
Max-Age=31536000; Path=/

I am a bit clueless why this behaviour is so unpredictable. Any ideas what 
might be going on here, or how to trace this?

Thanks,
Frederik

-- 
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/30d43532-b840-463a-93ff-5989045fc7d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelAdmin missing a couple of key features, or am I doing this wrong?

2016-09-16 Thread thauk
Apologies, I updated it.


class MyModelAdmin(ModelAdmin):
model = MyModel
form = MyForm
 
def get_form(self, request, obj=None, **kwargs):
form_class = super(MyModelAdmin, self).get_form(request, obj=obj, 
**kwargs)
 
some_parameter_for_one_thing = 
self.get_some_parameter_for_one_thing()
 
from django.forms.models import ModelFormMetaclass
class FormMetaclass(ModelFormMetaclass):
def __new__(mcs, name, bases, attrs):
attrs["some_parameter_for_one_thing"] = 
some_parameter_for_one_thing
return super(FormMetaclass, mcs).__new__(mcs, name, bases, 
attrs)
 
another_parameter_for_another_thing= 
obj.another_parameter_for_another_thing
 
import six
class FormWrapper(six.with_metaclass(FormMetaclass, form_class)):
def __init__(self, *args, **kwargs):
data = {"another_parameter_for_another_thing": 
six.text_type(another_parameter_for_another_thing)}
super(FormWrapper, self).__init__(data, *args, **kwargs)
 
return FormWrapper

On Friday, September 16, 2016 at 1:46:32 AM UTC-7, Andrea D'Amore wrote:
>
> On 16 September 2016 at 00:53,  > 
> wrote: 
> > I have a ModelAdmin subclass (code at: ) 
>
> Gives a 404: 
>
> The requested URL /0LAt was not found on this server. 
>
>
> I'm missing the rationale of using an external paste service while 
> you're already using a text-based medium, the mailing list, that's 
> able to accomodate what's (hopefully) a small code excerpt, in worst 
> case scenario I think it'll accept an attachment as well. 
>
> This also has the added bonus of getting archived and never result in 
> broken links and missing content, like it's likely to happen at some 
> point with external services. 
>
>
> -- 
> Andrea 
>

-- 
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/9481df50-3280-4b9d-87c2-080e632a4cda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Setting FK field in list view

2016-09-16 Thread RompePC
I'll try ASAP I can, thanks

El viernes, 16 de septiembre de 2016, 13:59:26 (UTC+2), ludovic coues 
escribió:
>
> Have you tried something like author__name ? Assuming a model with an 
> author foreign key. 
>
> 2016-09-16 8:56 GMT+02:00 RompePC >: 
> > I would like to pass to the list display view a FK field of the admin 
> form 
> > (like the ones when adding a new row). But I don't see the way of doing 
> it, 
> > although I've searched along many properties of the model admin to get 
> it. 
> > 
> > Anyone did something like that before? 
> > 
> > -- 
> > 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/d4cfbc3a-8668-4576-8d5c-c04cdd0eb1b2%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
> -- 
>
> Cordialement, Coues Ludovic 
> +336 148 743 42 
>

-- 
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/584f69b0-8086-400b-9af0-da5fabb706e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Setting FK field in list view

2016-09-16 Thread ludovic coues
Have you tried something like author__name ? Assuming a model with an
author foreign key.

2016-09-16 8:56 GMT+02:00 RompePC :
> I would like to pass to the list display view a FK field of the admin form
> (like the ones when adding a new row). But I don't see the way of doing it,
> although I've searched along many properties of the model admin to get it.
>
> Anyone did something like that before?
>
> --
> 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/d4cfbc3a-8668-4576-8d5c-c04cdd0eb1b2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

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


Re: Compressing images before saving to database

2016-09-16 Thread Javier Guerra Giraldez
On 16 September 2016 at 05:45, Isaac Tetteh  wrote:
> I have a project where users upload photos of any type. But i want to
> compress the images before saving them. Is pillow the best i can use or Is
> there a built in or 3rd party library to do this. Its link to documentation
> will be appreciated too.


I've used Wand (a binding to imagemagick library) on a background
task, since I had to handle HUGE images

-- 
Javier

-- 
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/CAFkDaoQk%3DG95yRsyMdmRN%2BMOEJ5os15nLzo7AZwTYEk9YUYW-Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: A public cloud with django backend

2016-09-16 Thread Andreas Kuhne
2016-09-15 9:21 GMT+02:00 Rahul Doshi :

> Hi ,I want to setup  a dropbox like server with django. So far i have
> achieved uploading files onto a location .I want these files to show up on
> browser which they do(while saving file to the location I indexed an entry
> in the Db so i just print the file names from the DB(POSTGRESQL).Now i want
> to provide users options to view or download the files.I put a link on it
> and tried ,it did not work since it shows an javascript error "NOT ALLOWED
> TO LOAD LOCAL RECOURCE" . All uploaded files are loaded in C drive of my
> laptop. Where else do i load so that javascript can load it? Attaching my
> code ..thanks in advance.
>
> Index.html
>
> http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/
> jquery.min.js">
> 
> function downloadFile(filename){
>
>
> }
> 
> 
> {% for i in q  %}
>
>{{i.id}}
>
>{{i.file_name}}
> file_name}}")">Download
>
>
>  {% endfor %}
> 
>  ="multipart/form-data">{% csrf_token %}
>  
> 
> 
>
> views.py
>
> from django.shortcuts import render
> from django.http import HttpResponse
> from django.shortcuts import render_to_response
> from polls.models import Files
> from os import walk
> from os.path import isfile, join
> def index(request):
> return render(request,"index.html", {})
>
> def upload(request):
> for x in request.FILES.getlist("files"):
> def process(f):
> with open(r'C:\Users\rdoshi\storage\%s ' %f.name , 'wb+') as destination:
> b = Files(file_name= f.name)
> b.save()
> for chunk in f.chunks():
> destination.write(chunk)
> process(x)
> q = Files.objects.all()
> return render(request,  "index.html", {'q' : q})
>
>
> --
> 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/b6396853-ae8f-4fef-ac91-7ab235eb22b0%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

Hi,

I think you should look at how the django storage system works
https://docs.djangoproject.com/el/1.10/ref/files/storage/.

You should store the files in the media directory of your app and not
directly on your harddrive in an arbitrary folder. Then you can serve the
files by using the url that you get from the file field in the model.

The way you have created it now the link goes to your local harddrive and
not to the server itself. If you where to run that on the internet, the
files would be located on the servers drive (to wherever you put the file
folder) and then when clicking on the link the users would be looking at
there own harddrive for the file.

Check https://docs.djangoproject.com/ja/1.10/ref/models/fields/#filefield
for more information about the filefield.

Regards,

Andréas

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


Compressing images before saving to database

2016-09-16 Thread Isaac Tetteh
hello,

I have a project where users upload photos of any type. But i want to 
compress the images before saving them. Is pillow the best i can use or Is 
there a built in or 3rd party library to do this. Its link to documentation 
will be appreciated too. 

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To 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/8b2ba24a-f339-4cc8-aab4-12a454cbab84%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelAdmin missing a couple of key features, or am I doing this wrong?

2016-09-16 Thread Andrea D'Amore
On 16 September 2016 at 00:53,   wrote:
> I have a ModelAdmin subclass (code at: )

Gives a 404:

The requested URL /0LAt was not found on this server.


I'm missing the rationale of using an external paste service while
you're already using a text-based medium, the mailing list, that's
able to accomodate what's (hopefully) a small code excerpt, in worst
case scenario I think it'll accept an attachment as well.

This also has the added bonus of getting archived and never result in
broken links and missing content, like it's likely to happen at some
point with external services.


-- 
Andrea

-- 
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/CAMonFrQ%2B2JYMPEaOXw-FM2Oj--BxjNNrqsO6isEDgFGf%3DHnd0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.