Re: Status 404 on css files when deploying Django Rest Framework on Heroku

2018-04-30 Thread Alberto Luebbert M.
Hello,

I have tried the same solution that you expose. And it just does not work.

The structure of my project is as follows:

| - db.sqlite3
| - Drive
| | - __init__.py
| | - __init __. pyc
| | - settings.py
| | - settings.pyc
| | - urls.py
| | - urls.pyc
| | - wsgi.py
| | - static
| `- wsgi.pyc
| - manage.py
`- users
| - admin.py
| - admin.pyc
| - apps.py
| - __init__.py
| - __init __. pyc
| - migrations
| | - __init__.py
| `- __init __. pyc
| - models.py
| - models.pyc
| - serializers.py
| - serializers.pyc
| - tests.py
| - urls.py
| - urls.pyc
| - views.py
`- views.pyc

and this is my in apache2:




Require all granted



WSGIDaemonProcess demodjango python-home = / home / ubuntu / developer 
python-path = / home / ubuntu / demodjango / Drive
WSGIProcessGroup demodjango
WSGIScriptAlias ​​/ /home/ubuntu/demodjango/Drive/wsgi.py


I still have 404 errors. I wish you could give me a sign :)

Greetings from Mexico,
Alberto


On Monday, March 5, 2018 at 1:46:56 PM UTC-6, Athanasios Garyfalos wrote:
>
> Hello again,
>
> I guess this is a very common question on new Api(s) with Django Rest 
> Framework.
>
> After spending 9 hours (just today the rest of the days do not count) I 
> finally managed to fixed it.
>
> I followed the solution from here (django rest-framework : can't get 
> static files 
> )
>  
> and I created in my settings this configurations:
>
> # Static files (CSS, JavaScript, Images)
> # https://docs.djangoproject.com/en/1.9/howto/static-files/
>
> PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
> STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
> STATIC_URL = '/static/'
>
> STATICFILES_DIRS = (
> ("js", os.path.join(STATIC_ROOT, 'js')),
> ("css", os.path.join(STATIC_ROOT, 'css')),
> ("images", os.path.join(STATIC_ROOT, 'images')),
> ("fonts", os.path.join(STATIC_ROOT, 'fonts')),
> )
>
> I also needed to create the directory under my STATIC_ROOT but this is 
> easy after running the command:
>
> python manage.py collectstatic
>
> It will complain where the statics should be stored and if a directory 
> does not exist it will mention it.
>
> I hope this will help someone else also in the future... :)
>
> BR / Thanos
>
> On Mon, Mar 5, 2018 at 12:55 PM, Athanasios Garyfalos  > wrote:
>
>> Hello everyone,
>>
>> I am new to Django Rest Framework and to REST in general.
>>
>> I followed the really nice REST-Tutorials 
>>  and I 
>> managed to make an API that on my local host is working perfectly.
>>
>> My problem is when I am deploying it on the Heroku I get 404 error 
>> regarding the Jana scripts css etc.
>>
>> I following the logs with (heroku logs --tail --app myApi) and I see the 
>> following: 
>>
>> 2018-03-05T11:38:18.629896+00:00 app[web.1]: - 10.104.55.179 - - 
>> [05/Mar/2018:12:38:18 +0100] "GET /static/rest_framework/js/default.js 
>> HTTP/1.1" 404 109 "https://myApi.herokuapp.com/"; "Mozilla/5.0 (X11; 
>> Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 
>> Safari/537.36"
>> 2018-03-05T11:38:18.690858+00:00 app[web.1]: - 10.104.55.179 - - 
>> [05/Mar/2018:12:38:18 +0100] "GET /favicon.ico HTTP/1.1" 404 85 "
>> https://myApi.herokuapp.com/"; "Mozilla/5.0 (X11; Linux x86_64) 
>> AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36"
>> 2018-03-05T11:38:18.692141+00:00 heroku[router]: - at=info method=GET 
>> path="/favicon.ico" host=myApi.herokuapp.com 
>> request_id=ec4d4ed0-19a9-4785-84b5-452e90239bfb fwd="5.59.34.149" 
>> dyno=web.1 connect=1ms service=3ms status=404 bytes=260 protocol=https
>> 2018-03-05T11:38:18.165004+00:00 heroku[router]: - at=info method=GET 
>> path="/static/rest_framework/css/prettify.css" host=myApi.herokuapp.com 
>> request_id=f9be6b23-eb9f-4efd-81e0-929772f0dac3 fwd="5.59.34.149" 
>> dyno=web.1 connect=0ms service=2ms status=404 bytes=288 protocol=https
>> 2018-03-05T11:38:18.205046+00:00 heroku[router]: - at=info method=GET 
>> path="/static/rest_framework/js/prettify-min.js" host=myApi.herokuapp.com 
>> request_id=385a1ec6-8951-4ac1-845a-757c600fff70 fwd="5.59.34.149" 
>> dyno=web.1 connect=1ms service=3ms status=404 bytes=290 protocol=https
>>
>> Sample of my tree structure:
>>
>> $ tree -L 2 myApi/
>> myApi/
>> ├── db.sqlite3
>> ├── env
>> │   ├── bin
>> │   ├── include
>> │   ├── lib
>> │   ├── local
>> │   └── pip-selfcheck.json
>> ├── manage.py
>> ├── Pipfile
>> ├── Pipfile.lock
>> ├── Procfile
>> ├── Procfile~
>> ├── README.md
>> ├── requirements.txt
>> ├── snippets
>> │   ├── admin.py
>> │   ├── admin.pyc
>> │   ├── apps.py
>> │   ├── apps.pyc
>> │   ├── __init__.py
>> │   ├── __init__.pyc
>> │   ├── migrations
>> │   ├── models.py
>> │   ├── models.pyc
>> │   ├── permissions.py
>> │   ├── permissions.pyc
>> │   ├── serializers.py
>> │   ├── serializers.pyc
>> │   ├── tests.py
>> │   ├── urls.py
>> │   ├── urls.pyc
>

Django 500 error view plaintext after DRF upgrade?

2018-04-30 Thread Caleb Mennen
I've been updating DRF for a project, 3.3.3->3.5.4. In doing this change, 
the standard django 500 error page that generates when DEBUG==true is now 
of the type text/plain, and no HTML is in the response. I've been able to 
narrow this down to happening between the 3.4.4 and 3.4.5 releases. Any 
ideas on why this might be happening?

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Rest Framework File Upload

2018-04-30 Thread ray
Thanks, but then blog explains what i've already done. You enter the fields 
explicitly. What i need is when you upload a file, the API extracts the 
package name  and package_version_code and displays as shown in the image 
above.

Any idea how i should modify the serializer?

Thanks.

On Monday, 30 April 2018 19:49:06 UTC+1, Prasanna Balaraman wrote:
>
> Follow the steps mentioned in this blog and you should be able to 
> accomplish it.
>
> https://blog.vivekshukla.xyz/uploading-file-using-api-django-rest-framework/
>
> Thanks,
>
> [image: freshworks-dew.png]
>
> Prasanna Balaraman
>
> Team Enabler
>
> p : +91-9940112996
>
> e : prasanna@freshworks.com 
>
> w : www.freshworks.com 
>
> [image: fb.png]  [image: twitter.png] 
>  [image: linkedin.png] 
> 
>
>  
>
>
> On Mon, Apr 30, 2018 at 11:50 PM ray > 
> wrote:
>
>> Hi everyone.I need to upload a file using the Rest Framework API.Im 
>> looking to extract then list the metadata (package_name & package version 
>> code) from an android application(apk file).
>>
>> This is what i have so far 
>>
>>
>> 
>> Here is my code so far. I can only do this through the admin, but i want 
>> it in such a way that when when file is uploaded,the serializer can 
>> get/extract the fields(package_name & package version code).
>>
>>
>> models.py
>>
>> from django.db import models 
>>
>> class Applist(models.Model): 
>> application = models.FileField(upload_to = 'uploads/') 
>> package_name = models.CharField(max_length=200) 
>> package_version_code = models.IntegerField(default=0)
>>
>>
>> serializers.py
>>
>>
>>
>> import os 
>> from rest_framework import serializersfrom . import models
>>
>>
>> class FileUploaderSerializer(serializers.ModelSerializer):
>> class Meta:
>> model = models.Applist
>> fields = ('application', 'package_name', 'package_version_code',)
>>
>> def validate(self, validated_data):
>> validated_data['name'] = 
>> os.path.splitext(validated_data['file'].name)[0]
>> #other validation logic
>> return validated_data
>>
>> def create(self, validated_data):
>> return FileUploader.objects.create(**validated_data)
>>
>>
>>
>>
>>
>>
>> views.py
>>
>>
>> from rest_framework import viewsetsfrom rest_framework.parsers import 
>> FormParser, MultiPartParser
>>
>> from . import modelsfrom . import serializers
>>
>>
>>
>> class FileUploaderViewSet(viewsets.ModelViewSet):
>> serializer_class = serializers.FileUploaderSerializer
>> parser_classes = (MultiPartParser, FormParser,)
>> queryset = models.Applist.objects.all()
>>
>> def get_queryset(self, *args, **kwargs):
>> qs = super(FileUploaderViewSet, self).get_queryset(*args, **kwargs)
>> # qs = qs.filter(owner=self.request.user)
>> return qs
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django REST framework" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-rest-framework+unsubscr...@googlegroups.com 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Rest Framework File Upload

2018-04-30 Thread Prasanna Balaraman
Follow the steps mentioned in this blog and you should be able to
accomplish it.
https://blog.vivekshukla.xyz/uploading-file-using-api-django-rest-framework/

Thanks,

[image: freshworks-dew.png]

Prasanna Balaraman

Team Enabler

p : +91-9940112996

e : prasanna.balara...@freshworks.com

w : www.freshworks.com 

[image: fb.png]  [image: twitter.png]
 [image: linkedin.png]





On Mon, Apr 30, 2018 at 11:50 PM ray  wrote:

> Hi everyone.I need to upload a file using the Rest Framework API.Im
> looking to extract then list the metadata (package_name & package version
> code) from an android application(apk file).
>
> This is what i have so far
>
>
> 
> Here is my code so far. I can only do this through the admin, but i want
> it in such a way that when when file is uploaded,the serializer can
> get/extract the fields(package_name & package version code).
>
>
> models.py
>
> from django.db import models
>
> class Applist(models.Model):
> application = models.FileField(upload_to = 'uploads/')
> package_name = models.CharField(max_length=200)
> package_version_code = models.IntegerField(default=0)
>
>
> serializers.py
>
>
>
> import os
> from rest_framework import serializersfrom . import models
>
>
> class FileUploaderSerializer(serializers.ModelSerializer):
> class Meta:
> model = models.Applist
> fields = ('application', 'package_name', 'package_version_code',)
>
> def validate(self, validated_data):
> validated_data['name'] = 
> os.path.splitext(validated_data['file'].name)[0]
> #other validation logic
> return validated_data
>
> def create(self, validated_data):
> return FileUploader.objects.create(**validated_data)
>
>
>
>
>
>
> views.py
>
>
> from rest_framework import viewsetsfrom rest_framework.parsers import 
> FormParser, MultiPartParser
>
> from . import modelsfrom . import serializers
>
>
>
> class FileUploaderViewSet(viewsets.ModelViewSet):
> serializer_class = serializers.FileUploaderSerializer
> parser_classes = (MultiPartParser, FormParser,)
> queryset = models.Applist.objects.all()
>
> def get_queryset(self, *args, **kwargs):
> qs = super(FileUploaderViewSet, self).get_queryset(*args, **kwargs)
> # qs = qs.filter(owner=self.request.user)
> return qs
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-rest-framework+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Rest Framework File Upload

2018-04-30 Thread ray
Hi everyone.I need to upload a file using the Rest Framework API.Im looking 
to extract then list the metadata (package_name & package version code) 
from an android application(apk file).

This is what i have so far 


Here is my code so far. I can only do this through the admin, but i want it 
in such a way that when when file is uploaded,the serializer can 
get/extract the fields(package_name & package version code).


models.py

from django.db import models 

class Applist(models.Model): 
application = models.FileField(upload_to = 'uploads/') 
package_name = models.CharField(max_length=200) 
package_version_code = models.IntegerField(default=0)


serializers.py



import os 
from rest_framework import serializersfrom . import models


class FileUploaderSerializer(serializers.ModelSerializer):
class Meta:
model = models.Applist
fields = ('application', 'package_name', 'package_version_code',)

def validate(self, validated_data):
validated_data['name'] = 
os.path.splitext(validated_data['file'].name)[0]
#other validation logic
return validated_data

def create(self, validated_data):
return FileUploader.objects.create(**validated_data)






views.py


from rest_framework import viewsetsfrom rest_framework.parsers import 
FormParser, MultiPartParser

from . import modelsfrom . import serializers



class FileUploaderViewSet(viewsets.ModelViewSet):
serializer_class = serializers.FileUploaderSerializer
parser_classes = (MultiPartParser, FormParser,)
queryset = models.Applist.objects.all()

def get_queryset(self, *args, **kwargs):
qs = super(FileUploaderViewSet, self).get_queryset(*args, **kwargs)
# qs = qs.filter(owner=self.request.user)
return qs

















-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


nice_name = serializers.CharField(source='Uglyfield') no longer working

2018-04-30 Thread Ross Crawford-d'Heureuse
Hi there,

Successfully installed djangorestframework-3.8.2

```
class CustomerCardSerializer(serializers.Serializer):
customer_id = serializers.CharField(source='customerID')
customer_uid = serializers.CharField(source='CustomerUID')
email = serializers.EmailField(source='CustomerEmail')
card = serializers.CharField(source='KundenKarteNr')
```


```
from blah.apps.default.serializers import CustomerCardSerializer

cc=CustomerCardSerializer(data={'MobileDC': None, 'CustomerUID': 
'88B6F5AA-3D7E-2EBE-B968-F73C3992083D', 'BasePoints': '10', 
'KundenKarteNr': '20088400056241905', 'KundenKarteKennz': 'DC', 
'CardStatus': '0', 'WebserviceOffline': 'false', 'CustomerEmail': None, 
'TotalPoints': '10', 'MobileDCStatus': None, 'CardType': '1', 
'UsableAccount': '296', 'CustomerScan': 'true', 'CurrentAccount': '296', 
'WebserviceTransaktionsID': '000201721020171804301730', 
'WebserviceErrorId': None, 'BlockedAccount': '0', 'customerID': '5261', 
'ExtraPoints': '0.0', 'PreviousCardNr': None})
>>> cc.is_valid()
False
>>> cc.errors
{'customer_id': [ErrorDetail(string=u'This field is required.', 
code=u'required')], 'customer_uid': [ErrorDetail(string=u'This field is 
required.', code=u'required')], 'email': [ErrorDetail(string=u'This field 
is required.', code=u'required')], 'card': [ErrorDetail(string=u'This field 
is required.', code=u'required')]}
```

If I change the serializer fieldnames to the UGLY field names works fine... 
but this is not what we want..

Has anyone been aware of new changes that may affect this in the 3.8.2 
release?

Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.