Django Captcha Ajax call not working

2017-03-26 Thread valerio orfano
I have the following class view taken from documentation:

class CaptchaView(CreateView):
template_name = "captcha.html"
form_class = MyForm

def form_invalid(self, form):
if self.request.is_ajax():
to_json_response = dict()
to_json_response['status'] = 0
to_json_response['form_errors'] = form.errors

to_json_response['new_cptch_key'] = CaptchaStore.generate_key()
to_json_response['new_cptch_image'] = 
captcha_image_url(to_json_response['new_cptch_key'])

return HttpResponse(json.dumps(to_json_response), 
content_type='application/json')
else:
return HttpResponse("test1", content_type='application/json')

def form_valid(self, form):
if self.request.is_ajax():
to_json_response = dict()
to_json_response['status'] = 1

to_json_response['new_cptch_key'] = CaptchaStore.generate_key()
to_json_response['new_cptch_image'] = 
captcha_image_url(to_json_response['new_cptch_key'])

return HttpResponse(json.dumps(to_json_response), 
content_type='application/json')
else:
return HttpResponse("test2", content_type='application/json')


and the following ajax call from template:


function captcha() {
$.ajax({
type: "POST",  
url: "../captcha",
contentType: "application/json",
data: {},
dataType: "json",
success: function(data) {
alert("success");
  },
error: function(data) {
alert("not OK");
  }

});
}





url(r'^captcha$', views.CaptchaView.as_view(), name="captcha")

Could you please help me to get a proper ajax call? When i click the OK 
button no success or error message is displayed!!!

Please help me out!!

thanx

valerio


-- 
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/2877f6c0-928a-47e1-8398-f57ef3200aba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: GeoDjango

2017-03-26 Thread Alex Mandel
I'll add that you could also use Geonode http://geonode.org/ which is a
Django front-end to a Geoserver instance.

I've also run Tilestache directly on GeoDjango tables stored in Postgis
to generate TMS style services.

Enjoy,
Alex

PS: GeoDjango has it's own mailing list.

On 03/20/2017 01:05 AM, Jani Tiainen wrote:
> Hi,
> 
> There are several options how to actually server maps.
> 
> Few simplest options are running seperate server that serves maps like
> MapServer, GeoServer or Mapnik.
> 
> Of course if you want to serve maps from Django directly that maybe tricky.
> 
> That django-wms package seems to leverage MapServer mapscript to publish
> maps. Not sure how mature that project is.
> 
> On 18.03.2017 14:51, Samuel Brunel wrote:
>> Hello,
>>
>> I’m new on GeoDjango, I need to known If I can use GeoDjango as  WMS ?
>>
>> Best regards,
>>
>> Samuel
>>
> 

-- 
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/206545b6-143a-34b6-68e0-74211fd5ed38%40wildintellect.com.
For more options, visit https://groups.google.com/d/optout.


Re: AdminURLFieldWidget question

2017-03-26 Thread Mike Dewhirst

Declaring myAdminURLFieldWidget outside the ModelAdmin class is the answer!

On 26/03/2017 6:32 PM, Mike Dewhirst wrote:
How can I manipulate the link in an Admin URLField so it uses the 
normal HTML hyperlink attributes?


I have a substance with ingredients in a self m2m relationship and I 
want the ingredients displayed to carry a link to open themself in 
another substance page.


IOW, I want to use the substance.name (ie, ingredient name) instead of 
substance.id in the URL.


Also, I don't need the user to see the input ("Change") part of the 
field because that is always done by the software.


I guess the answer is to sub-class the AdminURLFieldWidget and use 
that via ...


formfield_overrides = {

URLField: {'widget': myAdminURLFieldWidget},

}


However, I'm a bit lost in making it happen. Where do I learn more?

Thanks

Mike




--
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/4a49d908-2d2d-7335-6318-56b63c0a3d4b%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Channels - logout not resetting message.user value on new WebSocket connections

2017-03-26 Thread Andrew Godwin
This isn't a known issue, but I'll need more debugging info to know if it's
Channels or not. Couple of checks:

 - The way to reject a socket connection is "close": True, not "accept":
False; try changing to that
 - What is the value of message.user and message.reply_channel on each of a
a) correctly denied logged out request, b) correctly accepted logged in
request, c) incorrectly accepted logged out request after having just
logged out?

Andrew

On Sun, Mar 26, 2017 at 12:13 AM, Sergio Diaz 
wrote:

> Hello,
>
> I'm trying out Channels in Django 1.11 and set up a few consumers, looking
> like this:
>
> @channel_session_user_from_http
> def ws_connect(message, slug):
> if message.user.is_authenticated():
>  message.reply_channel.send({"accept": True})
> else:
>  message.reply_channel.send({"accept": False})
>
> And it works before logging in; the connection is closed and dropped when
> the user is logged out. Once logged in, it begins accepting socket
> connections.
>
> Then, I hit `accounts/logout` (the default login view), and everything
> logs out. I can't view protected (login_required) views anymore, and it
> seems like everything was unset properly.
>
> However, when I open up the console and fire another websocket request,
> the request passes the is_authenticated check and enters with the old
> logged out user, as if it was not cleared. This only happens within
> channels, every other part of the site is logged out, but this seems to
> retain the session and not clear it.
>
> Is there any solution to this, am I approaching this wrong, or is this a
> known issue?
>
> 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/ad49c85d-78f0-4420-acdf-c84ff02524b7%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/CAFwN1uoGvEFhvTSQEOtzZi2mBLQtBLrBJqrFbr_E%3D36KYtC0QQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing client's force_login method doesn't seem to be logging in.

2017-03-26 Thread Quentin Fulsher
Actually I just fixed it, You have to save the model after you set the 
password.

On Sunday, March 26, 2017 at 2:35:08 PM UTC-7, Quentin Fulsher wrote:
>
> I'm trying to write a test case for the viewing permissions on a certain 
> webpage. I'm trying to get the client to force_login as a user to test if 
> they can get the view or not. The issue is that my client doesn't seem to 
> be logged in. No matter who I try to login as (There are a few different 
> types of users to test) I get redirected to the login page. The view is 
> decorated with  login_required so this makes a little bit of sense but I'm 
> still not sure why its happening.
>
> Here's the code for my test case:
>
> class AvailabilityListTestCase(TestCase):
> def setUp(self):
> self.admin = User.objects.create(username='admin', email='
> ad...@sb.com', is_superuser=True, is_staff=True)
> self.admin.set_password('admin')
> self.student = User.objects.create(username='student', email='
> stud...@sb.com')
> self.student.set_password('student')
> self.student2 = User.objects.create(username='student2', email='
> stude...@sb.com')
> self.student2.set_password('student2')
> self.tutor = User.objects.create(username='tutor', email='
> tu...@sb.com')
> self.tutor.set_password('tutor')
> self.tutor2 = User.objects.create(username='tutor2', email='
> tut...@sb.com')
> self.tutor2.set_password('tutor2')
> self.student.tutor = self.tutor
> self.c = Client()
> self.url = '/user/tutor/availabilities/'
>
>
> def test_anon_access(self):
> response = self.c.get(self.url)
> self.assertRedirects(response, 
> '/user/login/?next=/user/tutor/availabilities/')
>
>
> def test_owner_access(self):
> self.c.force_login(self.tutor)
> response = self.c.get(self.url)
> self.assertEqual(200, response.status_code)
>
>
> Here's the view:
>
> @login_required
> def list_availabilities(request, username):
> curr_user = request.user
> if not curr_user.is_staff or curr_user.username != username:
> return HttpResponseForbidden()
> requested_user = get_object_or_404(User.objects.all(), username=
> username)
> requested_user_profile = get_user_profile(requested_user)
> availabilities = requested_user_profile.availability_set.all()
> formatted_list = []
> for availability in availabilities:
> formatted_list.append(
> (
> availability.title,
> # Format meaning: `12h:minute am/pm`
> availability.start_time.strftime("%l:%M %p"),
> availability.end_time.strftime("%l:%M %p"),
> )
> )
> return render(
> request,
> 'appointments/availability_list.html',
> {
> 'tutor_username':username,
> 'formatted_list':formatted_list,
> }
> )
>
>
>
> 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/c0244ed1-5fd6-4525-b13e-7b772a69b3ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Testing client's force_login method doesn't seem to be logging in.

2017-03-26 Thread Quentin Fulsher
I'm trying to write a test case for the viewing permissions on a certain 
webpage. I'm trying to get the client to force_login as a user to test if 
they can get the view or not. The issue is that my client doesn't seem to 
be logged in. No matter who I try to login as (There are a few different 
types of users to test) I get redirected to the login page. The view is 
decorated with  login_required so this makes a little bit of sense but I'm 
still not sure why its happening.

Here's the code for my test case:

class AvailabilityListTestCase(TestCase):
def setUp(self):
self.admin = User.objects.create(username='admin', email=
'ad...@sb.com', is_superuser=True, is_staff=True)
self.admin.set_password('admin')
self.student = User.objects.create(username='student', email=
'stud...@sb.com')
self.student.set_password('student')
self.student2 = User.objects.create(username='student2', email=
'stude...@sb.com')
self.student2.set_password('student2')
self.tutor = User.objects.create(username='tutor', email=
'tu...@sb.com')
self.tutor.set_password('tutor')
self.tutor2 = User.objects.create(username='tutor2', email=
'tut...@sb.com')
self.tutor2.set_password('tutor2')
self.student.tutor = self.tutor
self.c = Client()
self.url = '/user/tutor/availabilities/'


def test_anon_access(self):
response = self.c.get(self.url)
self.assertRedirects(response, 
'/user/login/?next=/user/tutor/availabilities/')


def test_owner_access(self):
self.c.force_login(self.tutor)
response = self.c.get(self.url)
self.assertEqual(200, response.status_code)


Here's the view:

@login_required
def list_availabilities(request, username):
curr_user = request.user
if not curr_user.is_staff or curr_user.username != username:
return HttpResponseForbidden()
requested_user = get_object_or_404(User.objects.all(), username=username
)
requested_user_profile = get_user_profile(requested_user)
availabilities = requested_user_profile.availability_set.all()
formatted_list = []
for availability in availabilities:
formatted_list.append(
(
availability.title,
# Format meaning: `12h:minute am/pm`
availability.start_time.strftime("%l:%M %p"),
availability.end_time.strftime("%l:%M %p"),
)
)
return render(
request,
'appointments/availability_list.html',
{
'tutor_username':username,
'formatted_list':formatted_list,
}
)



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/6009c52a-1a73-4460-9978-727ab10d0bb4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django allauth and AdminSite reverse()

2017-03-26 Thread Melvyn Sopacua
On Sunday 26 March 2017 09:11:25 Narnik Gamarnik wrote:
> Hello.
> 
> There is a task to create one entry point for different groups of
> users in Django, and after successfully passing authorization,
> redirect to the required page.
> 
> There are three different routes:

Yes, and the 4th is missing.
You could start by reading the fabulous manual[1]: the part in the bottom about 
"urls.py".


-- 
Melvyn Sopacua


[1] http://django-allauth.readthedocs.io/en/latest/installation.html

-- 
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/3300747.SUQFXxk0HD%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: How to create a new user with django rest framework and custom user model

2017-03-26 Thread Andréas Kühne
I think you have a few errors in your code.

In views.py you write:
User.objects.create_user(
serialized.save()
)

serialized.save() is probably calling User.objects.create - which you
shouldn't do. If you want to create a user the way you are doing you will
need to override the default create_user method on the User model. Add
support for handling the password1 and password2 fields and then add
support for the first_name and last_name fields.

Then you can override the create method on the serializer class like this:

def create(self, validated_data):
"""
Override default implementation of the create method. Make sure
user gets password.

:param validated_data: the validated data sent to the method

:return: the newly created user if successful
"""
if self.is_valid(True):
return User.create_user(validated_data.get("email"),
validated_data.get("password"),
validated_data.get("first_name"),
validated_data.get("last_name"))


Regards,

Andréas

2017-03-26 18:23 GMT+02:00 Aamu Padi :

> I have a custom user model and I am using django-rest-framework to create
> API
>
> models.py:
>
> class User(AbstractBaseUser, PermissionsMixin):
> email = models.EmailField(
> unique=True,
> max_length=254,
> )
> first_name = models.CharField(max_length=15)
> last_name = models.CharField(max_length=15)
> mobile = models.IntegerField(unique=True)
> date_joined = models.DateTimeField(default=timezone.now)
> is_active = models.BooleanField(default=True)
> is_admin = models.BooleanField(default=False)
>
>
> serializers.py:
>
> class UserSerializer(serializers.ModelSerializer):
> password1 = serializers.CharField(write_only=True)
> password2 = serializers.CharField(write_only=True)
>
> class Meta:
> model = User
> fields = ('first_name', 'last_name', 'email', 'mobile',
> 'password1', 'password2')
>
>
> views.py:
>
> @api_view(['POST'])
> @permission_classes((AllowAny,))
> def create_user(request):
> serialized = UserSerializer(data=request.data)
> if serialized.is_valid():
> User.objects.create_user(
> serialized.save()
> )
> return Response(serialized.data, status=status.HTTP_201_CREATED)
> else:
> return Response(serialized._errors, status=status.HTTP_400_BAD_
> REQUEST)
>
>
> However, when I try to create a new user I am getting this error:
>
> *Got a TypeError when calling User.objects.create(). This may be because
>> you have a writable field on the serializer class that is not a valid
>> argument to User.objects.create(). You may need to make the field
>> read-only, or override the UserSerializer.create() method to handle this
>> correctly.*
>
>
> This maybe because there's no password1 or password2 fields in the User
> model. But so, how can I create an API to create a new user using
> django-rest-framework?
>
> --
> 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/CAHSNPWtWmifpo6BuWQmp3-Y-pXyJAPBELf90MmeWLQBB9nGmyw%
> 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/CAK4qSCe5CqajAZs7wOdoRh7-yzj%3DZVxXpbDRas3znndubymddA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to create a new user with django rest framework and custom user model

2017-03-26 Thread Aamu Padi
I have a custom user model and I am using django-rest-framework to create
API

models.py:

class User(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(
unique=True,
max_length=254,
)
first_name = models.CharField(max_length=15)
last_name = models.CharField(max_length=15)
mobile = models.IntegerField(unique=True)
date_joined = models.DateTimeField(default=timezone.now)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)


serializers.py:

class UserSerializer(serializers.ModelSerializer):
password1 = serializers.CharField(write_only=True)
password2 = serializers.CharField(write_only=True)

class Meta:
model = User
fields = ('first_name', 'last_name', 'email', 'mobile',
'password1', 'password2')


views.py:

@api_view(['POST'])
@permission_classes((AllowAny,))
def create_user(request):
serialized = UserSerializer(data=request.data)
if serialized.is_valid():
User.objects.create_user(
serialized.save()
)
return Response(serialized.data, status=status.HTTP_201_CREATED)
else:
return Response(serialized._errors,
status=status.HTTP_400_BAD_REQUEST)


However, when I try to create a new user I am getting this error:

*Got a TypeError when calling User.objects.create(). This may be because
> you have a writable field on the serializer class that is not a valid
> argument to User.objects.create(). You may need to make the field
> read-only, or override the UserSerializer.create() method to handle this
> correctly.*


This maybe because there's no password1 or password2 fields in the User
model. But so, how can I create an API to create a new user using
django-rest-framework?

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


django allauth and AdminSite reverse()

2017-03-26 Thread Narnik Gamarnik
Hello.

There is a task to create one entry point for different groups of users in 
Django, and after successfully passing authorization, redirect to the 
required page.

There are three different routes:

Urlpatterns = [
Url (r '^ django-admin /', include (admin.site.urls)),
Url (r '^ custom_admin /', include ('gglobal.custom_admin.urls', 
namespace = 'custom_admin')),
Url (r '^ admin /', include (wagtailadmin_urls, namespace = 'cms')),
]


Since I'm doing the login using allauth, I need to override the 
DefaultAccountAdapter, which is responsible for the redirect after 
authenticating.

>From allauth.account.adapter import DefaultAccountAdapter
>From django.shortcuts import redirect, resolve_url
>From django.core.urlresolvers import reverse


Class AccountAdapter (DefaultAccountAdapter):
Def get_login_redirect_url (self, request):
Url = super (AccountAdapter, self) .get_login_redirect_url (request)
If request.user.has_perm ('auth.change_permission'):
Url = reverse ('admin: index')
Return url



But reverse () returns:

NoReverseMatch at / accounts / login /

Reverse for 'cms' with arguments '()' and keyword arguments '{}' not 
found. 0 pattern (s) tried: []


When trying to do the same thing with other admin boards.

What should I pass to args / kwargs to work? In django-admin, there is no 
namepace at all, but it works as it should.

Tell me how to do it right?

Surely someone has already solved a similar problem.

Thank you 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/07851f19-1166-438c-bf78-f04e9ae24ce0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django tutorial HTTP Error 404

2017-03-26 Thread ludovic coues
This might be the most often asked question on this mailing list.

I'm pretty sure the code is perfectly fine, but you missed a little
step in the tutorial.
The third line of the error message is saying you opened http://127.0.0.1:8000/
The "Write your first view" chapter finish with "Go to
http://localhost:8000/polls/ "
That's why you get an error.

2017-03-26 17:30 GMT+02:00 Melvyn Sopacua :
> On Sunday 26 March 2017 07:41:06 Paweł Balawender wrote:
>
>
>
>> I'm a Django newbie on Windows and try to follow its official tutorial
>
>> . I've done
>
>> everything - as I think - completely fine
>
>
>
> Almost. You're told to test runserver *before* creating the app. This is
> because the "it worked" page is a little magic that depends on DEBUG=True
> and only the admin urlpatterns registered.
>
>
>
> As soon as you add more urls the magic stops working and since you did not
> define a homepage url, it is a genuine 404.
>
>
>
> --
>
> Melvyn Sopacua
>
> --
> 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/7352927.CGXvrrnOJ1%40devstation.
>
> 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%2BTa_K2Se1EO03EoxSSY2YdpDqGkJ9D5UF6h2wYBJwmiFzA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Produces Python?

2017-03-26 Thread Andréas Kühne
If you want managed hosting, all you have to do is ask if they can host
django.

You normally install django in a virtualenvironment - so as long as they
allow virtual environments you are probably good to go. Most managed
servers that can install python work with Django - Django is a pretty well
known framework.

If you are not leaning towards a managed environment all you need is a
linux installation on the server - it's easiest to install on linux, but
can be done in windows as well.

Regards,

Andréas

2017-03-26 17:23 GMT+02:00 Ed Sutherland :

> I now understand the purpose and worth of Django. What, then, are the
> questions I need to ask potential hosts? I'm leaning toward Linode, but
> would also like affordable managed hosting.
>
>
>
>
>
>  On Sun, 26 Mar 2017 04:16:52 -0400 Lachlan Musicman
> wrote 
>
> If you take James' answer and expand it a little, take a look at a Python
> micro-framework like Pylons http://pylonsproject.org/
>
> It's smaller than Django and is a useful tool for a different type of
> website.
>
> For instance take Authentication and Authorization - logins. Not every
> site needs one. Django has it by default. If you don't need it, maybe
> Pylons is a better fit.
>
> But be aware - when you have to actually write some code that makes user
> accounts and logins happen in Pylons, that's when you will discover that
> Django's "batteries included" philosophy really works for some style of
> projects.
>
> cheers
> L.
>
> --
> The most dangerous phrase in the language is, "We've always done it this
> way."
>
> - Grace Hopper
>
> On 26 March 2017 at 15:52, James Bennett  wrote:
>
> Python is a programming language. You can use it to write many types of
> programs. For example, you can use it to write web applications (which run
> on a web server, respond to HTTP requests, store their data in a database,
> render HTML templates for output, etc.). But doing this from scratch would
> require you to write many modules of Python code yourself, in order to
> handle all the common and necessary parts of a typical web application.
>
> Django provides those things for you, already written, so that you do not
> need to write them yourself. Instead, you can write only the things which
> are truly unique to your specific application, and let already-written
> modules from Django handle the rest.
>
> --
> 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/CAL13Cg9n4Mk6W2QEG51yoY5cXn1tQ
> _N9ORhvv3k7GGCdW2Ob3A%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/CAGBeqiO9QJ9N9%3DCj%2BsEnCsEn%
> 2B02nwindxbzoYaxTY%2BV16vp%2BPQ%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/15b0b36f07b.1074fa8d511956.6981836782800680358%
> 40tburgnews.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.c

Re: Django tutorial HTTP Error 404

2017-03-26 Thread Melvyn Sopacua
On Sunday 26 March 2017 07:41:06 Paweł Balawender wrote:

> I'm a Django newbie on Windows and try to follow its official tutorial
> . I've done
> everything - as I think - completely fine

Almost. You're told to test runserver *before* creating the app. This is 
because the "it worked" page is a little magic that depends on 
DEBUG=True and only the admin urlpatterns registered.

As soon as you add more urls the magic stops working and since you did 
not define a homepage url, it is a genuine 404.

-- 
Melvyn Sopacua

-- 
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/7352927.CGXvrrnOJ1%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Django Produces Python?

2017-03-26 Thread Ed Sutherland




I now understand the purpose and worth of Django. What, then, are 
the questions I need to ask potential hosts? I'm leaning toward Linode, but 
would also like affordable managed hosting. On Sun, 26 Mar 2017 04:16:52 
-0400  Lachlan Musicman wrote If you take James' answer 
and expand it a little, take a look at a Python micro-framework like Pylons 
http://pylonsproject.org/It's smaller than Django and is a useful tool for a 
different type of website.For instance take Authentication and Authorization - 
logins. Not every site needs one. Django has it by default. If you don't need 
it, maybe Pylons is a better fit. But be aware - when you have to actually 
write some code that makes user accounts and logins happen in Pylons, that's 
when you will discover that Django's "batteries included" philosophy really 
works for some style of projects.cheersL.--The most dangerous phrase in the 
language is, "We've always done it this way."- Grace Hopper On 26 March 2017 at 
15:52, James Bennett  wrote:Python is a programming 
language. You can use it to write many types of programs. For example, you can 
use it to write web applications (which run on a web server, respond to HTTP 
requests, store their data in a database, render HTML templates for output, 
etc.). But doing this from scratch would require you to write many modules of 
Python code yourself, in order to handle all the common and necessary parts of 
a typical web application.Django provides those things for you, already 
written, so that you do not need to write them yourself. Instead, you can write 
only the things which are truly unique to your specific application, and let 
already-written modules from Django handle the rest.--  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/CAL13Cg9n4Mk6W2QEG51yoY5cXn1tQ_N9ORhvv3k7GGCdW2Ob3A%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/CAGBeqiO9QJ9N9%3DCj%2BsEnCsEn%2B02nwindxbzoYaxTY%2BV16vp%2BPQ%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/15b0b36f07b.1074fa8d511956.6981836782800680358%40tburgnews.com.
For more options, visit https://groups.google.com/d/optout.


Django tutorial HTTP Error 404

2017-03-26 Thread Paweł Balawender
Hi

I'm a Django newbie on Windows and try to follow its official tutorial 
. I've done 
everything - as I think - completely fine, but at the last step I get a 404 
Error, more precisely, that:

Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/

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

   1. ^polls/
   2. ^admin/

The current URL, , didn't match any of these.

You're seeing this error because you have DEBUG = True in your Django 
settings file. Change that to False, and Django will display a standard 404 
page.

My directories are laid out like that:

#venv - directory of my virtual environment
venv\

testico\

mysite\

 __pycache__

__init__.py

settings.py

urls.py

wsgi.py 

polls\

__pycache__ 

migrations

 __init__, admin, apps, models, test - .py 

 urls.py

views.py 

db.sqlite3

manage.py  

#virtual environment files and directories below

Include, Lib, Scripts, pyvenv.cfg


 where testico\mysite\urls.py is just copypasted from tutorial's page, so:

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]


and testico\polls\urls.py is copypasted too, so:

from django.conf.urls import url
from . import views

urlpatterns = [
url(r'^$', views.index, name='index'),
]



 views is a short code, copied too:

from django.shortcuts import render

# Create your views here.
from django.http import HttpResponse


def index(request):
return HttpResponse("Hello, world. You're at the polls index.")



Nothing could help, so, as you've seen higher, I've just copied everything 
from the official website.
Here is what do I do at command prompt:




and in my web browser, g chrome:




I have no idea what to do :/ I've read at least 5 answers to problems like 
mine on stackoverflow, but their solves dont solve that. Can you tell me 
why doesn't it work? I tried to run it outside of that venv directory, but 
it changes nothing.



-- 
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/bf7064c2-9f37-4378-8376-77ae22ddb16c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Channels - logout not resetting message.user value on new WebSocket connections

2017-03-26 Thread Sergio Diaz
Hello,

I'm trying out Channels in Django 1.11 and set up a few consumers, looking 
like this:

@channel_session_user_from_http
def ws_connect(message, slug):
if message.user.is_authenticated():
 message.reply_channel.send({"accept": True})
else:
 message.reply_channel.send({"accept": False})

And it works before logging in; the connection is closed and dropped when 
the user is logged out. Once logged in, it begins accepting socket 
connections.

Then, I hit `accounts/logout` (the default login view), and everything logs 
out. I can't view protected (login_required) views anymore, and it seems 
like everything was unset properly.

However, when I open up the console and fire another websocket request, the 
request passes the is_authenticated check and enters with the old logged 
out user, as if it was not cleared. This only happens within channels, 
every other part of the site is logged out, but this seems to retain the 
session and not clear it.

Is there any solution to this, am I approaching this wrong, or is this a 
known issue?

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/ad49c85d-78f0-4420-acdf-c84ff02524b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Produces Python?

2017-03-26 Thread Antonis Christofides
You can think of Django as just a library. We call it a "framework" because it
defines a whole way of working. Likewise, the Python standard library calls
unittest a "framework" and this is consistent, because unittest also defines a
whole way of working. But the difference between a framework and a library can
be blurred.

So when you deploy your app, you need to include the libraries on which it
depends, and Django is one of them.

Antonis Christofides
http://djangodeployment.com

On 03/26/2017 06:19 AM, Ed Sutherland wrote:
> Forgive me if this question is too basic, but I'm a relative newbie to
> programming frameworks. As I understand it, a framework is built to abstract
> common tasks within the native language (Python, PHP, Ruby, etc.) When
> development using a framework is complete, will the production version of the
> app still require the framework? For instance, would an app developed with
> Django need only Python, or the entire programming framework? (I haven't seen
> a suitable answer after searching.)
>
>
>
> -- 
> 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/15b089fd407.b63a65c5111765.2626315058617697641%40tburgnews.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/87111969-0b0b-d260-356e-a3e40a77a7ee%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Produces Python?

2017-03-26 Thread Melvyn Sopacua
On Sunday 26 March 2017 00:46:28 Ed Sutherland wrote:
> Wow. I had thought Django as an assistant to build python 
projects. If
> I need the framework along with whatever language, it 
seems like
> immense code-bloat. What, then, is the purpose of using 
frameworks?

This article[1] sums it up quite nicely.
-- 
Melvyn Sopacua


[1] 
https://hackernoon.com/use-django-or-end-up-building-a-django-6cce65eb7255#.nkw8i79ww

-- 
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/3871806.Hfu0lyn8gM%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Django Produces Python?

2017-03-26 Thread Lachlan Musicman
If you take James' answer and expand it a little, take a look at a Python
micro-framework like Pylons http://pylonsproject.org/

It's smaller than Django and is a useful tool for a different type of
website.

For instance take Authentication and Authorization - logins. Not every site
needs one. Django has it by default. If you don't need it, maybe Pylons is
a better fit.

But be aware - when you have to actually write some code that makes user
accounts and logins happen in Pylons, that's when you will discover that
Django's "batteries included" philosophy really works for some style of
projects.

cheers
L.

--
The most dangerous phrase in the language is, "We've always done it this
way."

- Grace Hopper

On 26 March 2017 at 15:52, James Bennett  wrote:

> Python is a programming language. You can use it to write many types of
> programs. For example, you can use it to write web applications (which run
> on a web server, respond to HTTP requests, store their data in a database,
> render HTML templates for output, etc.). But doing this from scratch would
> require you to write many modules of Python code yourself, in order to
> handle all the common and necessary parts of a typical web application.
>
> Django provides those things for you, already written, so that you do not
> need to write them yourself. Instead, you can write only the things which
> are truly unique to your specific application, and let already-written
> modules from Django handle the rest.
>
> --
> 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/CAL13Cg9n4Mk6W2QEG51yoY5cXn1tQ
> _N9ORhvv3k7GGCdW2Ob3A%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/CAGBeqiO9QJ9N9%3DCj%2BsEnCsEn%2B02nwindxbzoYaxTY%2BV16vp%2BPQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


AdminURLFieldWidget question

2017-03-26 Thread Mike Dewhirst
How can I manipulate the link in an Admin URLField so it uses the normal 
HTML hyperlink attributes?


I have a substance with ingredients in a self m2m relationship and I 
want the ingredients displayed to carry a link to open themself in 
another substance page.


IOW, I want to use the substance.name (ie, ingredient name) instead of 
substance.id in the URL.


Also, I don't need the user to see the input ("Change") part of the 
field because that is always done by the software.


I guess the answer is to sub-class the AdminURLFieldWidget and use that 
via ...


formfield_overrides = {

URLField: {'widget': myAdminURLFieldWidget},

}


However, I'm a bit lost in making it happen. Where do I learn more?

Thanks

Mike


--
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/5496a937-8e44-fc70-ec39-514e79ede142%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.