Re: How to disable django views in the browser

2021-03-10 Thread Kunal Solanke
Won't you end up stopping  multipart  requests in that case?

On Thu, Mar 11, 2021, 02:36 Ryan Nowakowski  wrote:

> On Wed, Mar 10, 2021 at 07:43:55AM -0800, Mostapha Bouderka wrote:
> > I'm working on a project with react and django; and want to use django
> > views to be used as information source only and not show a page on the
> > browser. For example, I have a pilot sign up page that uses a pilot
> create
> > view to provide information to the pilot model. I want the users to be
> able
> > to sign up only by using the sign up page, but if someone accesses the
> > create pilot view, he shouldn't see anything.
> > ( if the url is domain.com/sign-up, he can see the react form )
> > (if the url is domain.com/pilot/create, he shouldn't see anything or
> get an
> > error, this url should only be used by the react form)
>
> You can probably do something like:
>
> if not request.accept('application/json'):
> raise SuspiciousOperation("Sorry we only handle JSON")
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/20210310210601.GM15054%40fattuba.com
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOecAny0ZCrqmzfN_e9vrAShJ7RiV69M3N6GUAwUHen382kUaQ%40mail.gmail.com.


Re: How to disable django views in the browser

2021-03-10 Thread Ryan Nowakowski
On Wed, Mar 10, 2021 at 07:43:55AM -0800, Mostapha Bouderka wrote:
> I'm working on a project with react and django; and want to use django 
> views to be used as information source only and not show a page on the 
> browser. For example, I have a pilot sign up page that uses a pilot create 
> view to provide information to the pilot model. I want the users to be able 
> to sign up only by using the sign up page, but if someone accesses the 
> create pilot view, he shouldn't see anything.
> ( if the url is domain.com/sign-up, he can see the react form )
> (if the url is domain.com/pilot/create, he shouldn't see anything or get an 
> error, this url should only be used by the react form) 

You can probably do something like:

if not request.accept('application/json'):
raise SuspiciousOperation("Sorry we only handle JSON")

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20210310210601.GM15054%40fattuba.com.


Re: How to disable django views in the browser

2021-03-10 Thread Mostapha Bouderka
Alright i'll check it right now

Many thanks for the assistance.

On Wednesday, March 10, 2021 at 8:15:08 PM UTC kunalsol...@gmail.com wrote:

> Also you will need to add allowed hosts in djnago settung to stop requests 
> from untrusted origins
>
> On Thu, Mar 11, 2021, 01:43 Kunal Solanke  wrote:
>
>> By doing this you won't be able to stop the get requests from browser, 
>> but post requests can be stopped.
>>
>> On Thu, Mar 11, 2021, 01:42 Kunal Solanke  wrote:
>>
>>> Ok in that case, drf by default sets a browsableapi render on all of the 
>>> views and viewsets, either overide that in settings, or use 
>>> renderer_classes=(JSONRendere,) in views in which yiu want to stop it. 
>>>
>>> Search for BrowsableAPIRenderer. 
>>>
>>> Ig you should have mentioned drf sooner. 
>>>
>>>
>>>
>>>
>>> On Thu, Mar 11, 2021, 01:35 Mostapha Bouderka  
>>> wrote:
>>>
 I'am using the django rest framework


 On Wednesday, March 10, 2021 at 8:01:26 PM UTC kunalsol...@gmail.com 
 wrote:

> Idk the overall use case here ,
> But if the prject is reasonably bigger and you want to use class based 
> views, I'd suggest you to use drf. 
> But you if you don't want to use that,you will have to overide most to 
> the CBV given by djnango as most of them expect a success url or a 
> template 
> that they render. 
>
> If you are fine with functional views, do as kasper said,just use post 
> method. And moreover send JsonResponse .
>
> On Thu, Mar 11, 2021, 01:14 Kasper Laudrup  
> wrote:
>
>> On 10/03/2021 16.43, Mostapha Bouderka wrote:
>> > I'm working on a project with react and django; and want to use 
>> django 
>> > views to be used as information source only and not show a page on 
>> the 
>> > browser. For example, I have a pilot sign up page that uses a pilot 
>> > create view to provide information to the pilot model. I want the 
>> users 
>> > to be able to sign up only by using the sign up page, but if 
>> someone 
>> > accesses the create pilot view, he shouldn't see anything.
>> > ( if the url is domain.com/sign-up, he can see the react form )
>> > (if the url is domain.com/pilot/create, he shouldn't see anything 
>> or get 
>> > an error, this url should only be used by the react form)
>> > 
>> > I hope the question is clear and thanks in advance.
>> >
>>
>> If I understand correctly, wouldn't it work simply to look at the 
>> request method for the "domain.com/pilot/create" page and only 
>> return a 
>> response in case the method is POST very similar to any other form 
>> handling like this example:
>>
>>
>> https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view
>>
>> but leaving out the else branch and the default return (which would 
>> then 
>> make Django return an HTTP 405 error)?
>>
>> I don't know anything about React, but from a quick look at the 
>> documentation it like it's just normal HTTP forms using POST.
>>
>> Kind regards,
>>
>> Kasper Laudrup
>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/219471bc-d101-a13e-388f-25a0836e61ef%40stacktrace.dk
>> .
>>
> -- 
 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 view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/30357e43-13fd-404a-88a3-90ca135aeff7n%40googlegroups.com
  
 
 .

>>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f94b895f-e241-4529-80a5-d102212f11b5n%40googlegroups.com.


Re: How to disable django views in the browser

2021-03-10 Thread Kunal Solanke
Also you will need to add allowed hosts in djnago settung to stop requests
from untrusted origins

On Thu, Mar 11, 2021, 01:43 Kunal Solanke 
wrote:

> By doing this you won't be able to stop the get requests from browser, but
> post requests can be stopped.
>
> On Thu, Mar 11, 2021, 01:42 Kunal Solanke 
> wrote:
>
>> Ok in that case, drf by default sets a browsableapi render on all of the
>> views and viewsets, either overide that in settings, or use
>> renderer_classes=(JSONRendere,) in views in which yiu want to stop it.
>>
>> Search for BrowsableAPIRenderer.
>>
>> Ig you should have mentioned drf sooner.
>>
>>
>>
>>
>> On Thu, Mar 11, 2021, 01:35 Mostapha Bouderka 
>> wrote:
>>
>>> I'am using the django rest framework
>>>
>>>
>>> On Wednesday, March 10, 2021 at 8:01:26 PM UTC kunalsol...@gmail.com
>>> wrote:
>>>
 Idk the overall use case here ,
 But if the prject is reasonably bigger and you want to use class based
 views, I'd suggest you to use drf.
 But you if you don't want to use that,you will have to overide most to
 the CBV given by djnango as most of them expect a success url or a template
 that they render.

 If you are fine with functional views, do as kasper said,just use post
 method. And moreover send JsonResponse .

 On Thu, Mar 11, 2021, 01:14 Kasper Laudrup 
 wrote:

> On 10/03/2021 16.43, Mostapha Bouderka wrote:
> > I'm working on a project with react and django; and want to use
> django
> > views to be used as information source only and not show a page on
> the
> > browser. For example, I have a pilot sign up page that uses a pilot
> > create view to provide information to the pilot model. I want the
> users
> > to be able to sign up only by using the sign up page, but if someone
> > accesses the create pilot view, he shouldn't see anything.
> > ( if the url is domain.com/sign-up, he can see the react form )
> > (if the url is domain.com/pilot/create, he shouldn't see anything
> or get
> > an error, this url should only be used by the react form)
> >
> > I hope the question is clear and thanks in advance.
> >
>
> If I understand correctly, wouldn't it work simply to look at the
> request method for the "domain.com/pilot/create" page and only return
> a
> response in case the method is POST very similar to any other form
> handling like this example:
>
>
> https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view
>
> but leaving out the else branch and the default return (which would
> then
> make Django return an HTTP 405 error)?
>
> I don't know anything about React, but from a quick look at the
> documentation it like it's just normal HTTP forms using POST.
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/219471bc-d101-a13e-388f-25a0836e61ef%40stacktrace.dk
> .
>
 --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/30357e43-13fd-404a-88a3-90ca135aeff7n%40googlegroups.com
>>> 
>>> .
>>>
>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOecAnz4T5tYLBJrnVyJE5WJqPCMVXhEJmigbkJK_K%2BqekvxXg%40mail.gmail.com.


Re: How to disable django views in the browser

2021-03-10 Thread Kunal Solanke
By doing this you won't be able to stop the get requests from browser, but
post requests can be stopped.

On Thu, Mar 11, 2021, 01:42 Kunal Solanke 
wrote:

> Ok in that case, drf by default sets a browsableapi render on all of the
> views and viewsets, either overide that in settings, or use
> renderer_classes=(JSONRendere,) in views in which yiu want to stop it.
>
> Search for BrowsableAPIRenderer.
>
> Ig you should have mentioned drf sooner.
>
>
>
>
> On Thu, Mar 11, 2021, 01:35 Mostapha Bouderka 
> wrote:
>
>> I'am using the django rest framework
>>
>>
>> On Wednesday, March 10, 2021 at 8:01:26 PM UTC kunalsol...@gmail.com
>> wrote:
>>
>>> Idk the overall use case here ,
>>> But if the prject is reasonably bigger and you want to use class based
>>> views, I'd suggest you to use drf.
>>> But you if you don't want to use that,you will have to overide most to
>>> the CBV given by djnango as most of them expect a success url or a template
>>> that they render.
>>>
>>> If you are fine with functional views, do as kasper said,just use post
>>> method. And moreover send JsonResponse .
>>>
>>> On Thu, Mar 11, 2021, 01:14 Kasper Laudrup  wrote:
>>>
 On 10/03/2021 16.43, Mostapha Bouderka wrote:
 > I'm working on a project with react and django; and want to use
 django
 > views to be used as information source only and not show a page on
 the
 > browser. For example, I have a pilot sign up page that uses a pilot
 > create view to provide information to the pilot model. I want the
 users
 > to be able to sign up only by using the sign up page, but if someone
 > accesses the create pilot view, he shouldn't see anything.
 > ( if the url is domain.com/sign-up, he can see the react form )
 > (if the url is domain.com/pilot/create, he shouldn't see anything or
 get
 > an error, this url should only be used by the react form)
 >
 > I hope the question is clear and thanks in advance.
 >

 If I understand correctly, wouldn't it work simply to look at the
 request method for the "domain.com/pilot/create" page and only return
 a
 response in case the method is POST very similar to any other form
 handling like this example:


 https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view

 but leaving out the else branch and the default return (which would
 then
 make Django return an HTTP 405 error)?

 I don't know anything about React, but from a quick look at the
 documentation it like it's just normal HTTP forms using POST.

 Kind regards,

 Kasper Laudrup

 --
 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 view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/219471bc-d101-a13e-388f-25a0836e61ef%40stacktrace.dk
 .

>>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/30357e43-13fd-404a-88a3-90ca135aeff7n%40googlegroups.com
>> 
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOecAnztt-yDHsWHRECBarfmab1rUiQDLfs%3Dxy%2Bo7cW1u%3DXRDQ%40mail.gmail.com.


Re: How to disable django views in the browser

2021-03-10 Thread Kunal Solanke
Ok in that case, drf by default sets a browsableapi render on all of the
views and viewsets, either overide that in settings, or use
renderer_classes=(JSONRendere,) in views in which yiu want to stop it.

Search for BrowsableAPIRenderer.

Ig you should have mentioned drf sooner.




On Thu, Mar 11, 2021, 01:35 Mostapha Bouderka 
wrote:

> I'am using the django rest framework
>
>
> On Wednesday, March 10, 2021 at 8:01:26 PM UTC kunalsol...@gmail.com
> wrote:
>
>> Idk the overall use case here ,
>> But if the prject is reasonably bigger and you want to use class based
>> views, I'd suggest you to use drf.
>> But you if you don't want to use that,you will have to overide most to
>> the CBV given by djnango as most of them expect a success url or a template
>> that they render.
>>
>> If you are fine with functional views, do as kasper said,just use post
>> method. And moreover send JsonResponse .
>>
>> On Thu, Mar 11, 2021, 01:14 Kasper Laudrup  wrote:
>>
>>> On 10/03/2021 16.43, Mostapha Bouderka wrote:
>>> > I'm working on a project with react and django; and want to use django
>>> > views to be used as information source only and not show a page on the
>>> > browser. For example, I have a pilot sign up page that uses a pilot
>>> > create view to provide information to the pilot model. I want the
>>> users
>>> > to be able to sign up only by using the sign up page, but if someone
>>> > accesses the create pilot view, he shouldn't see anything.
>>> > ( if the url is domain.com/sign-up, he can see the react form )
>>> > (if the url is domain.com/pilot/create, he shouldn't see anything or
>>> get
>>> > an error, this url should only be used by the react form)
>>> >
>>> > I hope the question is clear and thanks in advance.
>>> >
>>>
>>> If I understand correctly, wouldn't it work simply to look at the
>>> request method for the "domain.com/pilot/create" page and only return a
>>> response in case the method is POST very similar to any other form
>>> handling like this example:
>>>
>>>
>>> https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view
>>>
>>> but leaving out the else branch and the default return (which would then
>>> make Django return an HTTP 405 error)?
>>>
>>> I don't know anything about React, but from a quick look at the
>>> documentation it like it's just normal HTTP forms using POST.
>>>
>>> Kind regards,
>>>
>>> Kasper Laudrup
>>>
>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/219471bc-d101-a13e-388f-25a0836e61ef%40stacktrace.dk
>>> .
>>>
>> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/30357e43-13fd-404a-88a3-90ca135aeff7n%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOecAnyY%2BMe%3Dd4EeNGSxN4AQ2vSzNnYZbFzS3ZZiPq7ztquwsg%40mail.gmail.com.


Re: How to disable django views in the browser

2021-03-10 Thread Mostapha Bouderka
I'am using the django rest framework


On Wednesday, March 10, 2021 at 8:01:26 PM UTC kunalsol...@gmail.com wrote:

> Idk the overall use case here ,
> But if the prject is reasonably bigger and you want to use class based 
> views, I'd suggest you to use drf. 
> But you if you don't want to use that,you will have to overide most to the 
> CBV given by djnango as most of them expect a success url or a template 
> that they render. 
>
> If you are fine with functional views, do as kasper said,just use post 
> method. And moreover send JsonResponse .
>
> On Thu, Mar 11, 2021, 01:14 Kasper Laudrup  wrote:
>
>> On 10/03/2021 16.43, Mostapha Bouderka wrote:
>> > I'm working on a project with react and django; and want to use django 
>> > views to be used as information source only and not show a page on the 
>> > browser. For example, I have a pilot sign up page that uses a pilot 
>> > create view to provide information to the pilot model. I want the users 
>> > to be able to sign up only by using the sign up page, but if someone 
>> > accesses the create pilot view, he shouldn't see anything.
>> > ( if the url is domain.com/sign-up, he can see the react form )
>> > (if the url is domain.com/pilot/create, he shouldn't see anything or 
>> get 
>> > an error, this url should only be used by the react form)
>> > 
>> > I hope the question is clear and thanks in advance.
>> >
>>
>> If I understand correctly, wouldn't it work simply to look at the 
>> request method for the "domain.com/pilot/create" page and only return a 
>> response in case the method is POST very similar to any other form 
>> handling like this example:
>>
>> https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view
>>
>> but leaving out the else branch and the default return (which would then 
>> make Django return an HTTP 405 error)?
>>
>> I don't know anything about React, but from a quick look at the 
>> documentation it like it's just normal HTTP forms using POST.
>>
>> Kind regards,
>>
>> Kasper Laudrup
>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/219471bc-d101-a13e-388f-25a0836e61ef%40stacktrace.dk
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/30357e43-13fd-404a-88a3-90ca135aeff7n%40googlegroups.com.


Re: How to disable django views in the browser

2021-03-10 Thread Mostapha Bouderka
Thanks for the reply.

However, your answer didn't really solve my issue.
The form i mentioned is just an example, in fact i have other views,. The 
issue is that i want those views to only handle information and send them 
bach to the front end, but if a user tries to access them through a 
browser, he either gets redirected to another page or gets an error message.

On Wednesday, March 10, 2021 at 7:44:26 PM UTC Kasper Laudrup wrote:

> On 10/03/2021 16.43, Mostapha Bouderka wrote:
> > I'm working on a project with react and django; and want to use django 
> > views to be used as information source only and not show a page on the 
> > browser. For example, I have a pilot sign up page that uses a pilot 
> > create view to provide information to the pilot model. I want the users 
> > to be able to sign up only by using the sign up page, but if someone 
> > accesses the create pilot view, he shouldn't see anything.
> > ( if the url is domain.com/sign-up, he can see the react form )
> > (if the url is domain.com/pilot/create, he shouldn't see anything or 
> get 
> > an error, this url should only be used by the react form)
> > 
> > I hope the question is clear and thanks in advance.
> >
>
> If I understand correctly, wouldn't it work simply to look at the 
> request method for the "domain.com/pilot/create" page and only return a 
> response in case the method is POST very similar to any other form 
> handling like this example:
>
> https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view
>
> but leaving out the else branch and the default return (which would then 
> make Django return an HTTP 405 error)?
>
> I don't know anything about React, but from a quick look at the 
> documentation it like it's just normal HTTP forms using POST.
>
> Kind regards,
>
> Kasper Laudrup
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dd57c808-7c3e-4dcf-b46f-30a5ab02d8a2n%40googlegroups.com.


Re: How to disable django views in the browser

2021-03-10 Thread Kunal Solanke
Please ignore typos.

On Thu, Mar 11, 2021, 01:30 Kunal Solanke 
wrote:

> Idk the overall use case here ,
> But if the prject is reasonably bigger and you want to use class based
> views, I'd suggest you to use drf.
> But you if you don't want to use that,you will have to overide most to the
> CBV given by djnango as most of them expect a success url or a template
> that they render.
>
> If you are fine with functional views, do as kasper said,just use post
> method. And moreover send JsonResponse .
>
> On Thu, Mar 11, 2021, 01:14 Kasper Laudrup  wrote:
>
>> On 10/03/2021 16.43, Mostapha Bouderka wrote:
>> > I'm working on a project with react and django; and want to use django
>> > views to be used as information source only and not show a page on the
>> > browser. For example, I have a pilot sign up page that uses a pilot
>> > create view to provide information to the pilot model. I want the users
>> > to be able to sign up only by using the sign up page, but if someone
>> > accesses the create pilot view, he shouldn't see anything.
>> > ( if the url is domain.com/sign-up, he can see the react form )
>> > (if the url is domain.com/pilot/create, he shouldn't see anything or
>> get
>> > an error, this url should only be used by the react form)
>> >
>> > I hope the question is clear and thanks in advance.
>> >
>>
>> If I understand correctly, wouldn't it work simply to look at the
>> request method for the "domain.com/pilot/create" page and only return a
>> response in case the method is POST very similar to any other form
>> handling like this example:
>>
>> https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view
>>
>> but leaving out the else branch and the default return (which would then
>> make Django return an HTTP 405 error)?
>>
>> I don't know anything about React, but from a quick look at the
>> documentation it like it's just normal HTTP forms using POST.
>>
>> Kind regards,
>>
>> Kasper Laudrup
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/219471bc-d101-a13e-388f-25a0836e61ef%40stacktrace.dk
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOecAnwkcDGf3vPuwq%2BP7q8NWxEcqaDBNHV_3DXZkSFR2oygQQ%40mail.gmail.com.


Re: How to disable django views in the browser

2021-03-10 Thread Kunal Solanke
Idk the overall use case here ,
But if the prject is reasonably bigger and you want to use class based
views, I'd suggest you to use drf.
But you if you don't want to use that,you will have to overide most to the
CBV given by djnango as most of them expect a success url or a template
that they render.

If you are fine with functional views, do as kasper said,just use post
method. And moreover send JsonResponse .

On Thu, Mar 11, 2021, 01:14 Kasper Laudrup  wrote:

> On 10/03/2021 16.43, Mostapha Bouderka wrote:
> > I'm working on a project with react and django; and want to use django
> > views to be used as information source only and not show a page on the
> > browser. For example, I have a pilot sign up page that uses a pilot
> > create view to provide information to the pilot model. I want the users
> > to be able to sign up only by using the sign up page, but if someone
> > accesses the create pilot view, he shouldn't see anything.
> > ( if the url is domain.com/sign-up, he can see the react form )
> > (if the url is domain.com/pilot/create, he shouldn't see anything or
> get
> > an error, this url should only be used by the react form)
> >
> > I hope the question is clear and thanks in advance.
> >
>
> If I understand correctly, wouldn't it work simply to look at the
> request method for the "domain.com/pilot/create" page and only return a
> response in case the method is POST very similar to any other form
> handling like this example:
>
> https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view
>
> but leaving out the else branch and the default return (which would then
> make Django return an HTTP 405 error)?
>
> I don't know anything about React, but from a quick look at the
> documentation it like it's just normal HTTP forms using POST.
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/219471bc-d101-a13e-388f-25a0836e61ef%40stacktrace.dk
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOecAnwasg%3DXnDYLpQPiXfZ7UEwKzr9townw%3DYixhZ4%3DvJagpQ%40mail.gmail.com.


Re: How to disable django views in the browser

2021-03-10 Thread Kasper Laudrup

On 10/03/2021 16.43, Mostapha Bouderka wrote:
I'm working on a project with react and django; and want to use django 
views to be used as information source only and not show a page on the 
browser. For example, I have a pilot sign up page that uses a pilot 
create view to provide information to the pilot model. I want the users 
to be able to sign up only by using the sign up page, but if someone 
accesses the create pilot view, he shouldn't see anything.

( if the url is domain.com/sign-up, he can see the react form )
(if the url is domain.com/pilot/create, he shouldn't see anything or get 
an error, this url should only be used by the react form)


I hope the question is clear and thanks in advance.



If I understand correctly, wouldn't it work simply to look at the 
request method for the "domain.com/pilot/create" page and only return a 
response in case the method is POST very similar to any other form 
handling like this example:


https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view

but leaving out the else branch and the default return (which would then 
make Django return an HTTP 405 error)?


I don't know anything about React, but from a quick look at the 
documentation it like it's just normal HTTP forms using POST.


Kind regards,

Kasper Laudrup

--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/219471bc-d101-a13e-388f-25a0836e61ef%40stacktrace.dk.