Friday, December 29, 2017

Re: Possible bug: OutputWrapper: TypeError: write() argument must be str, not bytes

hi,

i think your trying to write bytes instead of str. please have look at below example it might help you:
name = b'i_m byte bro'
print(name.decode('utf-8'))  // just decode the byte to str

o/p: i_m byte bro



On Fri, Dec 29, 2017 at 2:29 PM, emi <emidaruma@gmail.com> wrote:
Hello all!
I'm new to the list and mostly new to Django.

I am adding django-encrypted-model-fields to my Django project and one of the steps to install it is to generate a key using a ./manage.py command:
$ ./manage.py generate_encryption_key

When executing it, an error is raised:
Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/encrypted_model_fields/management/commands/generate_encryption_key.py", line 15, in handle
    self.stdout.write(key, ending=b'\n')
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 106, in write
    self._out.write(style_func(msg))
TypeError: write() argument must be str, not bytes


I have found a workaround for this, decoding output before writing to stdout, on django/core/management/base.py, line 106:

$ diff django/core/management/base.py-original django/core/management/base.py
106c106
<         self._out.write(style_func(msg))
---
>         self._out.write(style_func(msg).decode(self._out.encoding))

Do I have to do a pull request to Django or try to debug django-encrypted-model-fields and talk to their developers?

Thanks in advance!
em and best regardsi

--
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+unsubscribe@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/b7372388-ea45-4ec7-b62e-84d0540a365a%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+unsubscribe@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/CAGGVXBMrEkrOumsqm7b8tz0aQRJsH7rKi-qm%3DjBY8TO6m46iYg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

404 for some matching urls too (Version 2)

I do not know the mistake I am likely to be committing. In Django Version 2, I have a feeling that URL matching fails whenever there are query variables. 

When I try to log into Admin module, the login screen comes. But when a 'next' query variable is attached, I get a 404. Similarly when I try to jump to a page in the records listing, I get 404. (Color has been added for highlighting)

http://localhost:8000/admin/login/?next=/admin/

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

admin/ [name='index']
admin/ login/ [name='login']
admin/ logout/ [name='logout']
admin/ password_change/ [name='password_change']
admin/ password_change/done/ [name='password_change_done']
admin/ jsi18n/ [name='jsi18n']
admin/ r/<int:content_type_id>/<path:object_id>/ [name='view_on_site']
...... (corresponds to the tables defined)
admin/ ^(?P<app_label>rsi|auth)/$ [name='app_list']
login/ [name='login']
logout/ [name='logout']
authissue [name='authissue']
.....

The current path, admin/login/?next=/admin/, didn't match any of these.

Any help is appreciated.



--
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+unsubscribe@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/89e14511-03d3-43e8-9603-0aaccdf7ca91%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: DRF JWT Token with Mobile

instead of:
curl -X POST -d "mobile=1234567890" http://localhost:8000/api-token-auth/

could you just use:
curl -X POST -d "username=1234567890" http://localhost:8000/api-token-auth/

In any case what's the use case here? This doesn't seem secure at all, to log in someone only using the username, even more using a public know information

On Fri, Dec 29, 2017 at 8:21 AM, Andréas Kühne <andreas.kuhne@hypercode.se> wrote:
Hi,

You will have to implement your own authentication backend to make that work.

See here for an example:

Regards,

Andréas

2017-12-29 5:25 GMT+01:00 Mukul Mantosh <mukulmantosh91@gmail.com>:
Django Rest Framework JWT (http://getblimp.github.io/django-rest-framework-jwt/) as specified that JWT token can be obtained by passing username and password.

Example:
$ curl -X POST -d "username=admin&password=password123" http://localhost:8000/api-token-auth/

How to obtain the JWT Token using only mobile number. 
$ curl -X POST -d "mobile=1234567890" http://localhost:8000/api-token-auth/

Normally JWT works with the combination of username and password but i want the token using the mobile number only.


On Thursday, December 28, 2017 at 6:22:07 PM UTC+5:30, Krishnasagar Subhedarpage wrote:
Can you elaborate question? Please add some background for it.
---
Krishnasagar



On Thu, Dec 28, 2017 at 1:40 PM, Mukul Mantosh <mukulma...@gmail.com> wrote:
How to get JWT Token in DRF using only mobile number as the parameter instead of email and password..

--
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/1b3ae8bb-2039-4aa9-8a9f-2c4ddb2ffc55%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+unsubscribe@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/b0d5e227-7488-4c86-b757-681c287a1558%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+unsubscribe@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/CAK4qSCc1g6LP0dC%3DSAUzOD17A5dEkTYtTHM96EP6rgNS3XerUA%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+unsubscribe@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/CAFWa6t%2BLqAiRZ83osVUHqVQdcZ0-aqF8%2B94X8j3omep7Mwpy0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Possible bug: OutputWrapper: TypeError: write() argument must be str, not bytes

Hello all!
I'm new to the list and mostly new to Django.

I am adding django-encrypted-model-fields to my Django project and one of the steps to install it is to generate a key using a ./manage.py command:
$ ./manage.py generate_encryption_key

When executing it, an error is raised:
Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/encrypted_model_fields/management/commands/generate_encryption_key.py", line 15, in handle
    self.stdout.write(key, ending=b'\n')
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 106, in write
    self._out.write(style_func(msg))
TypeError: write() argument must be str, not bytes


I have found a workaround for this, decoding output before writing to stdout, on django/core/management/base.py, line 106:

$ diff django/core/management/base.py-original django/core/management/base.py
106c106
<         self._out.write(style_func(msg))
---
>         self._out.write(style_func(msg).decode(self._out.encoding))

Do I have to do a pull request to Django or try to debug django-encrypted-model-fields and talk to their developers?

Thanks in advance!
em and best regardsi

--
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+unsubscribe@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/b7372388-ea45-4ec7-b62e-84d0540a365a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Possible bug Django 2.0 CreateView generic CBV

Hi Steven,

Could you put a "import pdb; pdb.set_trace()" somewhere in your code?

This way it would be pretty easy to inspect where the code is breaking.

Besides, why upgrading to Class-based-views if your previous Django 1.11 implementation was working fine?

HTH

Etienne




Le 2017-12-28 à 20:44, Steven Meyer a écrit :
I hope I've got the right group this time. I originally posted it on Django core membership but Tim Graham emailed me to say it was the wrong group.

I am very new to Django - been at it for five weeks. Not sure whether this is a bug or my own stupidity.

Here is my model in an app called gcbv (for generic class-based view)

from django.db import models
from core.models import TimeStampModel
from django.urls import reverse
# Create your models here.

class Vehicle(TimeStampModel):
maker = models.CharField(max_length=100)
model_year = models.IntegerField()
vehicle_type = models.CharField(max_length=100)
slug = models.SlugField(max_length=100, unique=True)
vehicle_model = models.CharField(max_length=100)
website = models.URLField(max_length=100, blank=True)
email = models.EmailField(max_length=100, blank=True)
notes = models.TextField(blank=True, default='')
def __str__(self):
x = self.maker + ' ' + self.vehicle_model
return x

And here are the URLs

from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url
from . import views
from django.urls import reverse
#from django.views.generic.base import TemplateView

app_name = 'gcbv'

urlpatterns = [
    path('sub1/', views.SubView.as_view(), name='sub1'),
    path('vehicle_list/', views.VehicleListView.as_view(),
        name = 'vehicle_list'),
    path('vehicle/<str:slug>/', 
        views.VehicleDetailView.as_view(), 
        name='vehicle_detail'),
    path('vehicle/create', views.VehicleCreateView.as_view(),
        name='vehicle_create'),    
    path('', views.IndexTemplateView.as_view(), name='index'),
]

And here is the relevant view

class VehicleCreateView(CreateView):
model = Vehicle
fields = ['maker', 'model_year', 'vehicle_type', 'slug',
    'vehicle_model', 'website', 'email', 'notes']
labels = {'maker':'Maker', 'model_year':'Year', 
    'vehicle_type':'Type', 'vehicle_model':'Model',
    'website':'Website', 'email':'Email', 'notes':'Notes'}


Here is the template:

{% extends "core/base.html" %}
{% block body_block %}
<h1>Vehicle Create for GCBV</h1>

<form action="POST" action="">

  {% csrf_token %}
  {{ form.as_p }}
  <button name="submit" class="btn btn-primary">Submit</button>
</form>

<h1>End Vehicle Create for GCBV</h1>
{% endblock %}

I've attached screenshots of:

--The rendered form template

--What happens after I click submit

It looks as if the data is not being saved to the database.

If I add the same data from admin everything works fine. I've attached another screenshot showing that VehicleDetailView has found the relevant template and rendered the information.

Any help would be greatly appreciated.

NB: This all worked fine when I was using function views and regex instead of path.



--
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+unsubscribe@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/5aa037bb-25d5-442d-b1a6-b1bbc558dead%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--   Etienne Robillard  tkadm30@yandex.com  https://www.isotopesoftware.ca/

[SOS] Django-Oscar Front end(theme) replacement

Hi,

Does anybody use django-oscar to build a commerce website? I have done most of the things to make it online. But the default theme is ugly and not matched with the commodity's style.

We are a startup company and no UXD for the website design right now. Is there any other websites I can reference, and do a code based modification to get a better user experience?

Any feedback and suggestion is welcome, Thanks in advance! :)

The default theme is like below:

内嵌图片 1

Best Regards,
-Gary

--
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+unsubscribe@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/0100ca86-a562-4b57-a4c0-96bac855123c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thursday, December 28, 2017

Re: DRF JWT Token with Mobile

Hi,

You will have to implement your own authentication backend to make that work.

See here for an example:

Regards,

Andréas

2017-12-29 5:25 GMT+01:00 Mukul Mantosh <mukulmantosh91@gmail.com>:
Django Rest Framework JWT (http://getblimp.github.io/django-rest-framework-jwt/) as specified that JWT token can be obtained by passing username and password.

Example:
$ curl -X POST -d "username=admin&password=password123" http://localhost:8000/api-token-auth/

How to obtain the JWT Token using only mobile number. 
$ curl -X POST -d "mobile=1234567890" http://localhost:8000/api-token-auth/

Normally JWT works with the combination of username and password but i want the token using the mobile number only.


On Thursday, December 28, 2017 at 6:22:07 PM UTC+5:30, Krishnasagar Subhedarpage wrote:
Can you elaborate question? Please add some background for it.
---
Krishnasagar



On Thu, Dec 28, 2017 at 1:40 PM, Mukul Mantosh <mukulma...@gmail.com> wrote:
How to get JWT Token in DRF using only mobile number as the parameter instead of email and password..

--
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/1b3ae8bb-2039-4aa9-8a9f-2c4ddb2ffc55%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+unsubscribe@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/b0d5e227-7488-4c86-b757-681c287a1558%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+unsubscribe@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/CAK4qSCc1g6LP0dC%3DSAUzOD17A5dEkTYtTHM96EP6rgNS3XerUA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.