Re: Django foreign-key cannot assign must be a instance

2020-05-19 Thread Aldian Fazrihady
Use comp_id= instead of comp=

Regards,

Aldian Fazrihady
http://aldianfazrihady.com

Pada tanggal Sel, 19 Mei 2020 13.49, ratnadeep ray 
menulis:

> Hi all,
>
> I am trying to add a row in the DB using the following views.py:
>
> # Create your views here.
>> from django.shortcuts import render
>> from fusioncharts.models import Component,Report
>> import xlrd
>> def pie_chart(request):
>> labels = []
>> data = []
>> loc = ("C:\Django_apps\QRC_Report.xlsx")
>> workbook = xlrd.open_workbook(loc)
>> worksheet = workbook.sheet_by_name('Sheet1')
>> num_rows = worksheet.nrows - 1
>> num_cols = worksheet.ncols - 1
>> curr_row = -1
>> component = []
>> comp = None
>> while curr_row < num_rows:
>>   curr_row += 1
>>   row = worksheet.row(curr_row)
>>   curr_col = -1
>>   if "Header" in worksheet.cell_value(curr_row, 0):
>> compon = worksheet.cell_value(curr_row, 0).strip("*")
>> print("The component is %s" %compon)
>> component.append(compon)
>> print("===The results of the component %s is as
>> follows" %compon)
>> Component.objects.create(comp=compon)
>> continue
>>   while curr_col < num_cols:
>> curr_col += 1
>> cell_value = worksheet.cell_value(curr_row, curr_col)
>> #print("Cell value = %s" %cell_value)
>> test_name = worksheet.cell_value(curr_row,0)
>> print("Test name = %s" %test_name)
>> test_value = worksheet.cell_value(curr_row,1)
>> print("Test result = %s" %test_value)
>> print("The component is = %s" %comp)
>>
>> *Report.objects.create(param=test_name,comp=compon,value=test_value)*
>> return render(request, 'pie_chart.html', {
>> 'labels': labels,
>> 'data': data,
>> })
>
>
> However the above highlighted line is throwing the following error:
>
>> Cannot assign "'Header SQL Detailed'": "Report.comp" must be a
>> "Component" instance.
>
>
> My model is as follows:
>
> from django.db import models
>> from django.urls import reverse
>> from decimal import Decimal
>> # Create your models here.
>> class Component(models.Model):
>> comp = models.CharField(max_length=30)
>> class Report(models.Model):
>> comp = models.ForeignKey(Component,on_delete=models.CASCADE)
>> param = models.CharField(max_length=30)
>> value =
>> models.DecimalField(max_digits=25,decimal_places=18,default=Decimal('0.'))
>
>
>
> Can anyone please point out what is going wrong here? What should be the
> correction?
>
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/afb5a06a-0d7d-4038-a0fc-3c2aadbbe4fc%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/CAN7EoAYVn9nkZWF8_8BJS_Jei3pJXkigRemtSkKSVOczP1mf-g%40mail.gmail.com.


Re: Django foreign-key cannot assign must be a instance

2020-05-19 Thread ratnadeep ray
Can you please say in which line we should make that change because in so 
many places I am using comp. So in all the places should I change that ?

On Tuesday, 19 May 2020 12:36:19 UTC+5:30, Aldian Fazrihady wrote:
>
> Use comp_id= instead of comp=
>
> Regards, 
>
> Aldian Fazrihady
> http://aldianfazrihady.com
>
> Pada tanggal Sel, 19 Mei 2020 13.49, ratnadeep ray  > menulis:
>
>> Hi all, 
>>
>> I am trying to add a row in the DB using the following views.py: 
>>
>> # Create your views here.
>>> from django.shortcuts import render
>>> from fusioncharts.models import Component,Report
>>> import xlrd
>>> def pie_chart(request):
>>> labels = []
>>> data = []
>>> loc = ("C:\Django_apps\QRC_Report.xlsx")
>>> workbook = xlrd.open_workbook(loc) 
>>> worksheet = workbook.sheet_by_name('Sheet1')
>>> num_rows = worksheet.nrows - 1
>>> num_cols = worksheet.ncols - 1
>>> curr_row = -1
>>> component = []
>>> comp = None 
>>> while curr_row < num_rows:
>>>   curr_row += 1
>>>   row = worksheet.row(curr_row)
>>>   curr_col = -1
>>>   if "Header" in worksheet.cell_value(curr_row, 0):
>>> compon = worksheet.cell_value(curr_row, 0).strip("*")
>>> print("The component is %s" %compon)
>>> component.append(compon)
>>> print("===The results of the component %s is as 
>>> follows" %compon)
>>> Component.objects.create(comp=compon)
>>> continue
>>>   while curr_col < num_cols:
>>> curr_col += 1
>>> cell_value = worksheet.cell_value(curr_row, curr_col)
>>> #print("Cell value = %s" %cell_value)
>>> test_name = worksheet.cell_value(curr_row,0)
>>> print("Test name = %s" %test_name)
>>> test_value = worksheet.cell_value(curr_row,1)
>>> print("Test result = %s" %test_value)
>>> print("The component is = %s" %comp)
>>> 
>>> *Report.objects.create(param=test_name,comp=compon,value=test_value)*
>>> return render(request, 'pie_chart.html', {
>>> 'labels': labels,
>>> 'data': data,
>>> })
>>
>>
>> However the above highlighted line is throwing the following error: 
>>
>>> Cannot assign "'Header SQL Detailed'": "Report.comp" must be a 
>>> "Component" instance.
>>
>>
>> My model is as follows: 
>>
>> from django.db import models
>>> from django.urls import reverse
>>> from decimal import Decimal
>>> # Create your models here.
>>> class Component(models.Model):
>>> comp = models.CharField(max_length=30)
>>> class Report(models.Model):
>>> comp = models.ForeignKey(Component,on_delete=models.CASCADE)
>>> param = models.CharField(max_length=30)
>>> value = 
>>> models.DecimalField(max_digits=25,decimal_places=18,default=Decimal('0.'))
>>
>>
>>
>> Can anyone please point out what is going wrong here? What should be the 
>> correction? 
>>
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/afb5a06a-0d7d-4038-a0fc-3c2aadbbe4fc%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/1425af8b-7dae-4cdb-ba8a-82d0a9fa0a74%40googlegroups.com.


Re: required help to save SECRET_KEY and Third party Private API key

2020-05-19 Thread Anirudh choudhary
thanks for your answer

after your answer, I have tried to edit the ~/.profile file and
/etc/profile/ but still, I can't see my key inside my VM instance

i am putting

SECRET_KEY="jhsgdjadtad876s87dsadsad7sa"

in the above file .but when i run the command "env" i can see my key

thankyou

On Tue, May 19, 2020 at 10:54 AM Akshat Zala  wrote:

> You can refer the link below:
>
> 1. https://cloud.google.com/community/tutorials/secrets-manager-python
>
> On Tuesday, 19 May 2020 10:26:17 UTC+5:30, Anirudh choudhary wrote:
>>
>> Hello everyone
>>
>> I am hosting my website on google cloud platform on Ubuntu VM instance. I
>> cannot find a way to set the environment variable in the machine
>>
>> Like when I type on my local machine os.environ.get("SECRET_KEY") it give
>> me the key but when I type the same command on VM instance it shows me null
>>
>> I have tried some method like to edit the
>> 1./etc/environment
>> 2.~/.bashrc
>> but none of the files is giving me the secret Key
>>
>> waiting for expert answer
>>
>> thankyou
>>
> --
> 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/0e4dbe3c-7b38-4e61-8e64-f96dc2c44dd3%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/CAL8_rkHAv1qmfW%3DzWao92cHs2jDFsSGNEv21Fg%3D6FF%3DAo8PjuA%40mail.gmail.com.


Re: Django foreign-key cannot assign must be a instance

2020-05-19 Thread Aldian Fazrihady
replace
```
Report.objects.create(param=test_name,comp=compon,value=test_value)
```
with
```
Report.objects.create(param=test_name,comp_id=compon,value=test_value)
```

On Tue, May 19, 2020 at 2:39 PM ratnadeep ray  wrote:

> Can you please say in which line we should make that change because in so
> many places I am using comp. So in all the places should I change that ?
>
> On Tuesday, 19 May 2020 12:36:19 UTC+5:30, Aldian Fazrihady wrote:
>>
>> Use comp_id= instead of comp=
>>
>> Regards,
>>
>> Aldian Fazrihady
>> http://aldianfazrihady.com
>>
>> Pada tanggal Sel, 19 Mei 2020 13.49, ratnadeep ray 
>> menulis:
>>
>>> Hi all,
>>>
>>> I am trying to add a row in the DB using the following views.py:
>>>
>>> # Create your views here.
 from django.shortcuts import render
 from fusioncharts.models import Component,Report
 import xlrd
 def pie_chart(request):
 labels = []
 data = []
 loc = ("C:\Django_apps\QRC_Report.xlsx")
 workbook = xlrd.open_workbook(loc)
 worksheet = workbook.sheet_by_name('Sheet1')
 num_rows = worksheet.nrows - 1
 num_cols = worksheet.ncols - 1
 curr_row = -1
 component = []
 comp = None
 while curr_row < num_rows:
   curr_row += 1
   row = worksheet.row(curr_row)
   curr_col = -1
   if "Header" in worksheet.cell_value(curr_row, 0):
 compon = worksheet.cell_value(curr_row, 0).strip("*")
 print("The component is %s" %compon)
 component.append(compon)
 print("===The results of the component %s is as
 follows" %compon)
 Component.objects.create(comp=compon)
 continue
   while curr_col < num_cols:
 curr_col += 1
 cell_value = worksheet.cell_value(curr_row, curr_col)
 #print("Cell value = %s" %cell_value)
 test_name = worksheet.cell_value(curr_row,0)
 print("Test name = %s" %test_name)
 test_value = worksheet.cell_value(curr_row,1)
 print("Test result = %s" %test_value)
 print("The component is = %s" %comp)

 *Report.objects.create(param=test_name,comp=compon,value=test_value)*
 return render(request, 'pie_chart.html', {
 'labels': labels,
 'data': data,
 })
>>>
>>>
>>> However the above highlighted line is throwing the following error:
>>>
 Cannot assign "'Header SQL Detailed'": "Report.comp" must be a
 "Component" instance.
>>>
>>>
>>> My model is as follows:
>>>
>>> from django.db import models
 from django.urls import reverse
 from decimal import Decimal
 # Create your models here.
 class Component(models.Model):
 comp = models.CharField(max_length=30)
 class Report(models.Model):
 comp = models.ForeignKey(Component,on_delete=models.CASCADE)
 param = models.CharField(max_length=30)
 value =
 models.DecimalField(max_digits=25,decimal_places=18,default=Decimal('0.'))
>>>
>>>
>>>
>>> Can anyone please point out what is going wrong here? What should be the
>>> correction?
>>>
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/afb5a06a-0d7d-4038-a0fc-3c2aadbbe4fc%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/1425af8b-7dae-4cdb-ba8a-82d0a9fa0a74%40googlegroups.com
> 
> .
>


-- 
Regards,

Aldian Fazrihady
http://aldianfazrihady.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/CAN7EoAZ%2BnrQSbpcwx8-PbYyvTNLE1X%3DpfLH0ifVb2KrR3zRsEw%40mail.gmail.com.


Re: CouchDB as Django backend database

2020-05-19 Thread Akshat Zala
You can refer to the link below:

1. https://stackoverflow.com/a/50521563/4511992

On Friday, 15 May 2020 19:46:52 UTC+5:30, Gopesh Shriwas wrote:
>
> Hi All,
>
> Can anybody help me on using couchdb as a django backend database. I went 
> though with multiple options available on the internet like 
> django-couchbase , django-cbtools but didn't find suitable with python3.x 
> and django3.x. python-cloudant looks fine to be used as standard client 
> library to interact with couchdb but my requirement is to use couchdb as 
> full fledged django ORM.
>
> It will be very helpful if somebody can suggest me a better package which 
> can be preferred or any other approach to fulfill these requirements.
>
> Thanks,
> Gopesh
>

-- 
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/f1bedc39-ce0d-43ca-99cc-7241048cb3c8%40googlegroups.com.


RE: Re: required help to save SECRET_KEY and Third party Private API key

2020-05-19 Thread Vishesh Mangla
Why don’t you use the decouple module? Use it and add it to your gitignore.  Sent from Mail for Windows 10 From: Anirudh choudharySent: 19 May 2020 13:14To: django-users@googlegroups.comSubject: Re: required help to save SECRET_KEY and Third party Private API key thanks for your answer  after your answer, I have tried to edit the ~/.profile file and /etc/profile/ but still, I can't see my key inside my VM instance  i am putting  SECRET_KEY="jhsgdjadtad876s87dsadsad7sa"  in the above file .but when i run the command "env" i can see my key  thankyou  On Tue, May 19, 2020 at 10:54 AM Akshat Zala  wrote:You can refer the link below: 1. https://cloud.google.com/community/tutorials/secrets-manager-python On Tuesday, 19 May 2020 10:26:17 UTC+5:30, Anirudh choudhary wrote:Hello everyone  I am hosting my website on google cloud platform on Ubuntu VM instance. I cannot find a way to set the environment variable in the machine  Like when I type on my local machine os.environ.get("SECRET_KEY") it give me the key but when I type the same command on VM instance it shows me null  I have tried some method like to edit the 1./etc/environment 2.~/.bashrc but none of the files is giving me the secret Key  waiting for expert answer  thankyou -- 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/0e4dbe3c-7b38-4e61-8e64-f96dc2c44dd3%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/CAL8_rkHAv1qmfW%3DzWao92cHs2jDFsSGNEv21Fg%3D6FF%3DAo8PjuA%40mail.gmail.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/5ec39d35.1c69fb81.be2f9.1767%40mx.google.com.


How to pass a variable to views from a template using href ?

2020-05-19 Thread ratnadeep ray
Hi all, 

My requirement is to pass a variable to the view from the template using 
href. 

For example, I have written the following line of code: 

SQL data


So using the above line, can we send the value "SQL" clicking on the link 
of "SQL data" to the method "execute" written in the views? If not, then 
what way can I do so? 

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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7e892826-f4c1-426d-bf9b-1a1b0b2b17be%40googlegroups.com.


Re: Getting HTTP 301 on static resources

2020-05-19 Thread Andréas Kühne
You need to configure apache correctly and set up your static url in django.

See here for an explanation:
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/modwsgi/#serving-files

Regards,

Andréas


Den tis 19 maj 2020 kl 03:38 skrev jtaylor___ :

> I'm setting up a Django instance running with gunicorn, behind Apache.
> Running on the server, the initial page comes up at http://server_host/dj/,
> but all the static resources give a Status Code "301 Moved Permanently".
> Here's an example URL:
> http://server_host/dj/static/app_name/bootstrap/css/app_name-bootstrap.min.css
> .
>
> In PyCharm with "manage.py runserver", the initial page loads and the same
> static resource (
> http://127.0.0.1/static/app_name/bootstrap/css/app_name-bootstrap.min.css)
> loads fine.
>
> I spent a while on Google, but I guess I don't know how to properly write
> the search to find a solution.
>
> Any suggestions?  TIA
>
> --
> 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/46757a62-69d5-46fb-a259-23d92e796783%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/CAK4qSCcXUA8-iU9K1vb3G7jEhj%2BDFALn1fXTVXaR4AqHSZk4zQ%40mail.gmail.com.


Re: HOW TO PROTECT SOURCE CODE DEPLOYED TO A REMOTE SERVER

2020-05-19 Thread Andréas Kühne
You can't really do that with Python - however - IF you want to go down
that route, you can just use the pyc files - you can theoretically
backwards compile them, but I think this is the most you can do

Regards,

Andréas


Den tis 19 maj 2020 kl 03:36 skrev Sunday Iyanu Ajayi :

> I get your point but my solution is kind of a  SaaS Application. the
> client wants to host it on his controlled server  and if they get the
> source code, they can replicate, modify and maybe sell it.  Is there a way
> to host the compiled file or lock the directory to the project.
> *AJAYI Sunday *
> (+234) 806 771 5394
> *sunnexaj...@gmail.com *
>
>
>
> On Mon, May 18, 2020 at 9:28 PM Jim Armstrong 
> wrote:
>
>> When I work on client projects, I deploy to a test server that is under
>> my control. Once the project is complete and they have paid the invoice, I
>> deploy to the production server under their control. At that point, I don't
>> care if they have access to the code - my contracts give the clients all
>> rights to the project code upon completion of the project.
>>
>>
>> On Friday, May 15, 2020 at 9:22:33 AM UTC-4, Sunday Iyanu Ajayi wrote:
>>>
>>> I am working for a client that wants to deploy a project I am working on
>>> in a remote server and I will like to project my source code when deployed
>>> so that they will not be able to mess with it.
>>>
>>> How can  I  go about it please?
>>>
>>> *AJAYI Sunday *
>>> (+234) 806 771 5394
>>> *sunne...@gmail.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/636f0636-30df-4ce2-8629-2be8b208ec37%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/CAKYSAw3Hqjuz5rD_AsZ5Wa%2B3WBzQ9LN0GzZKHx3D-irztJ1G0A%40mail.gmail.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/CAK4qSCfz5H%3DQq%2BMXZtiLyAT35rhbSpLW3h0Z_5Jieoab3z37yA%40mail.gmail.com.


RE: How to pass a variable to views from a template using href ?

2020-05-19 Thread Vishesh Mangla
In your views.py check “dir” on request.GET object to see what you have got.  Sent from Mail for Windows 10 From: ratnadeep raySent: 19 May 2020 18:44To: Django usersSubject: How to pass a variable to views from a template using href ? Hi all,  My requirement is to pass a variable to the view from the template using href.  For example, I have written the following line of code:  value="SQL">SQL data So using the above line, can we send the value "SQL" clicking on the link of "SQL data" to the method "execute" written in the views? If not, then what way can I do so?  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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7e892826-f4c1-426d-bf9b-1a1b0b2b17be%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/5ec3ddc5.1c69fb81.fa4e6.ace5%40mx.google.com.


Re: Getting HTTP 301 on static resources

2020-05-19 Thread jtaylor___
Unfortunately, my Apache doesn't support wsgi.  I'm using ProxyPass in 
Apache.  It's working to bring back the pages, just not the static content 
like CSS & JS.

-- 
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/b27fd89d-bbd6-4968-ac92-9defc1917384%40googlegroups.com.


Re: How to pass a variable to views from a template using href ?

2020-05-19 Thread Desh Deepak
You can use slug

On Tue, 19 May 2020, 6:44 pm ratnadeep ray,  wrote:

> Hi all,
>
> My requirement is to pass a variable to the view from the template using
> href.
>
> For example, I have written the following line of code:
>
> SQL data
>
>
> So using the above line, can we send the value "SQL" clicking on the link
> of "SQL data" to the method "execute" written in the views? If not, then
> what way can I do so?
>
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7e892826-f4c1-426d-bf9b-1a1b0b2b17be%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/CAJ0m4xiv67vWFfQGqub73TJeb2ekfCaqg%2BO3RoirSbM6ADYPpg%40mail.gmail.com.


NEW TO DJANGO

2020-05-19 Thread Madhav Nandan
Dear Django fellas,

I'm new to Django here. I started learning and it's been a while and I'm
facing a lot of issues. Can somebody help me with *''how can I integrate a
payment system like PayPal to a link?''*
 Like I have a link, if someone clicks on that link that will redirect the
user to the payment page and there on the payment provider works.

I just need to get started and somebody can guide me here hopefully. I
don't' need code or so.

Help me here.

Best regards,




-- 
Madhav Nandan
cell: 9170459494
Skype: gaurav.kumar3992

-- 
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/CAGXYL6JYzv%3DvTRNXc1ZqSvJ-6S%3DOSJt%2B%3D_%3DhLqvwyaD0Z_NoDA%40mail.gmail.com.


RE: NEW TO DJANGO

2020-05-19 Thread Vishesh Mangla
Your question is not clear to me. What exactly do you want ?You do not require django to go to a site , rather you require a hyperlink.  Sent from Mail for Windows 10 From: Madhav NandanSent: 19 May 2020 20:34To: django-users@googlegroups.comSubject: NEW TO DJANGO Dear Django fellas, I'm new to Django here. I started learning and it's been a while and I'm facing a lot of issues. Can somebody help me with ''how can I integrate a payment system like PayPal to a link?'' Like I have a link, if someone clicks on that link that will redirect the user to the payment page and there on the payment provider works. I just need to get started and somebody can guide me here hopefully. I don't' need code or so. Help me here. Best regards,-- Madhav Nandancell: 9170459494Skype: gaurav.kumar3992 -- 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/CAGXYL6JYzv%3DvTRNXc1ZqSvJ-6S%3DOSJt%2B%3D_%3DhLqvwyaD0Z_NoDA%40mail.gmail.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/5ec3f74c.1c69fb81.5e199.c04c%40mx.google.com.


Integrate wepay payments in django site

2020-05-19 Thread Shyam Acharjya
greetings,

has anyone here have any prior experience in integrating wepay to a django 
site? if yes please share the process it would be a really big help

regards.

-- 
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/88ffd85e-8fdd-4b2c-b925-75f3fc3cf324%40googlegroups.com.


using mod_python and django3.02??

2020-05-19 Thread Robert O.
I wrote a django site (django3.02) and want to deploy it using mod_python. 
Is that even doable/ reasonable?. Do I need to use django version <1.5? 


-- 
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/9f7ec51b-8b9b-4f00-a48d-b5e54e4c38c9%40googlegroups.com.


How To create a chatroom in django

2020-05-19 Thread meera gangani
.

-- 
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/cc6df2ea-f7ce-442a-8dd5-21e9625a1e48%40googlegroups.com.


Re: Marketing django project

2020-05-19 Thread Md Russel
Derails  please.

On Tue, 19 May 2020 02:28 Fred XU, <18611615...@163.com> wrote:

> Hi,
>
> Do you need Chinese guys for this project?
>
> Fred
>
> 发自我的iPhone
>
> 在 2020年5月18日,21:44,maninder singh Kumar  写道:
>
> 
> Dear all,
>
> Require sales and marketing interns for django, javascript based
> artificial intelligence project.
>
> regards
> willy
> +91 9910669700
>
> --
> 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/CABOHK3TYdfAAeY%3DE5sdQsBpzwNSNKXtR%2BZGVd7u7txSqHszw7Q%40mail.gmail.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/F321446E-B7F1-44BD-9DBC-836BC68C4AAF%40163.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/CALRA69yetSoR%2BO_wFsRHHKJU9fvWXs653%3DnUY4mvDCMHXGFW8g%40mail.gmail.com.


Re: How to pass a variable to views from a template using href ?

2020-05-19 Thread Ignat Petrov
You should be able to do that by using a relative path instead of the 
absolute "/execute". Just use something like href="{% url 'execute' 'SQL' 
%}. For this to work you need to name the url path as 'execute'. That way 
you'll pass the 'SQL' value to the endpoint.
Here is example from the polls tutorial: 
https://docs.djangoproject.com/en/3.0/intro/tutorial03/

-- 
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/67447115-2534-420f-a433-672cd644d1b1%40googlegroups.com.


Re: Marketing django project

2020-05-19 Thread Md Russel
Hi,

Details  please.

Russel

On Tue, 19 May 2020 10:35 Md Russel,  wrote:

> Derails  please.
>
> On Tue, 19 May 2020 02:28 Fred XU, <18611615...@163.com> wrote:
>
>> Hi,
>>
>> Do you need Chinese guys for this project?
>>
>> Fred
>>
>> 发自我的iPhone
>>
>> 在 2020年5月18日,21:44,maninder singh Kumar  写道:
>>
>> 
>> Dear all,
>>
>> Require sales and marketing interns for django, javascript based
>> artificial intelligence project.
>>
>> regards
>> willy
>> +91 9910669700
>>
>> --
>> 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/CABOHK3TYdfAAeY%3DE5sdQsBpzwNSNKXtR%2BZGVd7u7txSqHszw7Q%40mail.gmail.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/F321446E-B7F1-44BD-9DBC-836BC68C4AAF%40163.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/CALRA69z5GnQHu-Q%2Bs79_V1pr%3DzrAcrLzMj3APkmfx99XhRhsTA%40mail.gmail.com.


Re: I'm new to this django help me out

2020-05-19 Thread meera gangani
You can watch django tutorial series on youtube
otherwise you can also apply to the courses on coursera or udemy

On Tuesday, May 5, 2020 at 10:55:48 PM UTC+5:30, sree lekha wrote:
>
>

-- 
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/9bd4397f-12d9-4816-b8ce-4a43d597612a%40googlegroups.com.


How To create a chatroom in django

2020-05-19 Thread Tobi DEGNON
You can use something like django channel, it is use to create asynchronous app 
like chat application

-- 
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/4a5d7a6a-4f51-4a9c-88a7-150df32db490%40googlegroups.com.


Can't Fix the No Reverse Error in Ajax

2020-05-19 Thread Ahmed Khairy


I am trying to use Ajax to submit a like button, I believe everything is in 
order but I keep getting django.urls.exceptions.NoReverseMatch: Reverse for 
'like_post' with arguments '('',)' not found. 1 pattern(s) tried: 
['score/like/(?P[0-9]+)$']


I am not sure what is the reason. Need help to identify the error.


Here is the view


class PostDetailView(DetailView):
model = Post
template_name = "post_detail.html"

def get_context_data(self, *args, **kwargs):
context = super(PostDetailView, self).get_context_data()
stuff = get_object_or_404(Post, id=self.kwargs['pk'])
total_likes = stuff.total_likes()
liked = False
if stuff.likes.filter(id=self.request.user.id).exists():
liked = True
context["total_likes"] = total_likes
context["liked"] = liked
return context


def LikeView(request, pk):
# post = get_object_or_404(Post, id=request.POST.get('post_id'))
post = get_object_or_404(Post, id=request.POST.get('id'))
like = False
if post.likes.filter(id=request.user.id).exists():
post.likes.remove(request.user)
like = False
else:
post.likes.add(request.user)
like = True
context["total_likes"] = total_likes
context["liked"] = liked

if request.is_ajax:
html = render_to_string('like_section.html', context, request=
request)
return JsonResponse({'form': html})

Here is the url.py updated

urlpatterns = [
path('user/', UserPostListView.as_view(), name=
'user-posts'),
path('', PostListView.as_view(), name='score'),
path('who_we_Are/', who_we_are, name='who_we_are'),
path('/', PostDetailView.as_view(), name='post-detail'),
path('like/', LikeView, name='like_post'),
path('new/', PostCreateView.as_view(), name='post-create'),
path('/update/', PostUpdateView.as_view(), name='post-update'),
path('/delete/', PostDeleteView.as_view(), name='post-delete')
]

here is the template


{% csrf_token %}
 Likes: {{total_likes}}  
{% if user.is_authenticated %}
{% if liked %}
 Unlike 
{% else %}
 Like 
{% endif  %}
{% else %}
 Login to Like 
{% endif %}   
   

here is the ajax

https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";>


$(document).ready(function(event){
$(document).on.('click','#like', function(event){
event.preventDefault();
$var pk= $(this).attr('value');
$.ajax({
type:'POST',
url:'{% url "score:like_post" post.pk %}',
data:{'id': pk, 'csrfmiddlewaretoken':'{{csrf_token}}'},
dataType:'json', 
success:function(response){
$('#like-section').html(response['form'])
console.log($('#like-section').html(response['form'
]));
},
error:function(rs, e){
console.log(rs.responseText);   
},
});
});
});



-- 
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/5aaa1274-dd6b-42bc-8a5e-bce4596ace98%40googlegroups.com.


Re: Getting HTTP 301 on static resources

2020-05-19 Thread jtaylor___
Someone suggested to have Apache handle the static content, and that solved 
my problem.

Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cd15dd88-e26d-4284-bcc8-afe3fd06120c%40googlegroups.com.


Re: PROBLEM WITH Multiple SETTINGS.PY FILE

2020-05-19 Thread Jorge Gimeno
I'm not sure why you're getting an exception.  I know the import mechanism
in Python 2 was a bit different, so I'm not sure if that's the issue or if
Django's import mechanism isn't finding your settings file.

I don't know if you have tried this, but I saw a blog post on using
multiple settings files.  Maybe it will help:
https://simpleisbetterthancomplex.com/tips/2017/07/03/django-tip-20-working-with-multiple-settings-modules.html

I hope this helps!

-Jorge

On Mon, May 18, 2020 at 6:51 PM chaitanya orakala 
wrote:

> I tried that way, sir. but it's of no use. I don't know how to resolve
> this issue. its been troubling me for 3 days now
>
> On Mon, May 18, 2020 at 9:29 PM Mike Dewhirst 
> wrote:
>
>> On 19/05/2020 11:10 am, chaitanya orakala wrote:
>> > I am using Python 2.7
>>
>> It is possible you need a top line in the file like this ...
>>
>> from __future__ import absolute_import
>>
>> I haven't been following this thread so someone may have mentioned that
>> already.
>>
>>
>> --
>> 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/95afb956-98f8-6664-9107-d0935b75cf6c%40dewhirst.com.au
>> .
>>
> --
> 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/CAPcTzRZHgBG1Q90Rk8VmNS%2ByzmQLd1bdq8ZPgA6A%2Bumsx4CGvw%40mail.gmail.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/CANfN%3DK9MAMn3WezyhMU5Rrv5DWWFNxQ0jc9RnfyK-qyCOiV%2BeA%40mail.gmail.com.


Re: Categories and shoe Subcategories according to the parent category.

2020-05-19 Thread saqlain abbas
Please tell me if anyone knows about this.

On Mon, May 18, 2020 at 4:50 PM saqlain abbas 
wrote:

> Hi, if i add Categories , for example
> 1)accessories
> 2)sports
> 3)books
> Subcategories:
> accessories is the parent category
> child categories are
> watches
> jewlry
> caps
> how can i show if  user selects the parent category accessories then the
> subcategories show according to parent categories like subcategories are
> watches jewlry etc
>
> --
> 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/1530c511-072f-44ee-83fa-3555bd090a89%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/CAP6Ddn3zr%2BsfaL6DGMHb-xsLpE1zKcToKjKEqoPU6PCgGqjh1w%40mail.gmail.com.


Re: Categories and shoe Subcategories according to the parent category.

2020-05-19 Thread Antje Kazimiers
you could have a field "parent" in your Model Category which is a
ForeignKey to Category itself, so Category is a self-referencing table.

Then in your first dropdown you only show those entries where parent is
None and in your second one where parent == accessories.

you need to get this right with your view which would be
show_child_categories where you pass the id of your parent and filter
for it in your view function.

hope that helps, antje

On 5/17/20 11:21 PM, saqlain abbas wrote:
> Hi, if i add Categories , for example 
> 1)accessories
> 2)sports
> 3)books
> Subcategories:
> accessories is the parent category
> child categories are 
> watches
> jewlry
> caps 
> how can i show if  user selects the parent category accessories then
> the subcategories show according to parent categories like
> subcategories are watches jewlry etc
> -- 
> 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/1530c511-072f-44ee-83fa-3555bd090a89%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/a28636f4-1dbc-b622-e2ce-3a0010625978%40gmail.com.


Re: Categories and shoe Subcategories according to the parent category.

2020-05-19 Thread Clive Bruton

There are django modules for hierarchical navigation

https://djangopackages.org/grids/g/navigation/


-- Clive


On 19 May 2020, at 23:20, saqlain abbas wrote:


Please tell me if anyone knows about this.

On Mon, May 18, 2020 at 4:50 PM saqlain abbas  
 wrote:

Hi, if i add Categories , for example
1)accessories
2)sports
3)books
Subcategories:
accessories is the parent category
child categories are
watches
jewlry
caps
how can i show if  user selects the parent category accessories  
then the subcategories show according to parent categories like  
subcategories are watches jewlry etc


--
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/1530c511-072f-44ee-83fa-3555bd090a89% 
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/CAP6Ddn3zr%2BsfaL6DGMHb- 
xsLpE1zKcToKjKEqoPU6PCgGqjh1w%40mail.gmail.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/3E93BF89-D7B4-4715-A666-30EAE076418B%40indx.co.uk.


Re: PROBLEM WITH Multiple SETTINGS.PY FILE

2020-05-19 Thread chaitanya orakala
Thank Jeorge. I went through that blog long back but I can't find a
relation to my Error. I will try contacting my manager regarding this. will
let you know if I find anything. Have a great day


On Tue, May 19, 2020 at 2:44 PM Jorge Gimeno  wrote:

> I'm not sure why you're getting an exception.  I know the import mechanism
> in Python 2 was a bit different, so I'm not sure if that's the issue or if
> Django's import mechanism isn't finding your settings file.
>
> I don't know if you have tried this, but I saw a blog post on using
> multiple settings files.  Maybe it will help:
> https://simpleisbetterthancomplex.com/tips/2017/07/03/django-tip-20-working-with-multiple-settings-modules.html
>
> I hope this helps!
>
> -Jorge
>
> On Mon, May 18, 2020 at 6:51 PM chaitanya orakala <
> chaitu.orak...@gmail.com> wrote:
>
>> I tried that way, sir. but it's of no use. I don't know how to resolve
>> this issue. its been troubling me for 3 days now
>>
>> On Mon, May 18, 2020 at 9:29 PM Mike Dewhirst 
>> wrote:
>>
>>> On 19/05/2020 11:10 am, chaitanya orakala wrote:
>>> > I am using Python 2.7
>>>
>>> It is possible you need a top line in the file like this ...
>>>
>>> from __future__ import absolute_import
>>>
>>> I haven't been following this thread so someone may have mentioned that
>>> already.
>>>
>>>
>>> --
>>> 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/95afb956-98f8-6664-9107-d0935b75cf6c%40dewhirst.com.au
>>> .
>>>
>> --
>> 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/CAPcTzRZHgBG1Q90Rk8VmNS%2ByzmQLd1bdq8ZPgA6A%2Bumsx4CGvw%40mail.gmail.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/CANfN%3DK9MAMn3WezyhMU5Rrv5DWWFNxQ0jc9RnfyK-qyCOiV%2BeA%40mail.gmail.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/CAPcTzRaZCKqFZ-smQwNscYtmivyt1_tHhvF94wyN60LVHu4Wvw%40mail.gmail.com.


Re: PROBLEM WITH Multiple SETTINGS.PY FILE

2020-05-19 Thread Mike Dewhirst
I thought I'd go back and look at your original post. Your settings file 
looks a bit tricky.


I learned to deal with multiple settings files a long time ago so I 
don't know what current best practice is. Essentially, the way I do it 
is to have a complete base.py with all settings in a default state for 
security and production components. Then I have all my separate settings 
files ...


from base import *

... followed by the adjusted settings for that environment. Typically 
they will be production.py, staging.py and local.py


Then depending on the environment my wsgi.py imports settings.production 
or settings.mike-local or whatever.


It looks to me as though you are doing the opposite. Your wsgi.py 
imports a single settings file which has a massive if/elif block to 
import one of a multitude of other settings files each of which imports 
the equivalent of my base.py (your settings_common.py)


My mechanism has a single import statement while yours has at least two.

I think your wsgi.py should have the massive if/elif block to simply 
name the correct settings file (based on the host name) whenever the web 
server reloads.


It might reduce importing complexity somewhat and possibly solve the 
problem.


My settings arrangement is

base - all the settings as defaults
production - all the production settings no matter which host
staging - all the staging settings no matter which host
local - all the local settings including detecting the OS, setting DEBUG 
switching off security etc

local-mike - all my own settings including sqlite for faster testing
local-test - including postgreSQL for rigorous testing

I also needed to simulate environments. My mechanism is to rename the 
project directory and detect that in my settings.base.py like this ...


if deploy_dir == 'bis': # pragma: no cover
    PRODUCTION = "pq3"    # hostname
    DOMAIN = 'djfghdsgdlg.com'
    BRANDING = 'BIS'
    BRAND_URL = 'https://www.{0}/'.format(DOMAIN)
    ADMIN_URL = 'https://pay.{0}/admin'.format(DOMAIN)
    ALLOWED_HOSTS = [u'pay.{0}'.format(DOMAIN)]
    FUNCTION = 'invoice'
elif deploy_dir == 'cli': # pragma: no cover
    etc etc

I also wrote a couple of utilities which are called from dev versions of 
my settings files. They print out all settings which significantly 
change between hosts depending on which host I'm simulating.


In summary, I don't think I can help just by looking at the error - 
other than the obvious error being reported in a settings file - but I 
would definitely try and simplify the importing. And I do like to print 
out all the essential settings every time runserver reloads.


Good luck

M



On 20/05/2020 9:59 am, chaitanya orakala wrote:
Thank Jeorge. I went through that blog long back but I can't find a 
relation to my Error. I will try contacting my manager regarding this. 
will let you know if I find anything. Have a great day



On Tue, May 19, 2020 at 2:44 PM Jorge Gimeno > wrote:


I'm not sure why you're getting an exception.  I know the import
mechanism in Python 2 was a bit different, so I'm not sure if
that's the issue or if Django's import mechanism isn't finding
your settings file.

I don't know if you have tried this, but I saw a blog post on
using multiple settings files.  Maybe it will help:

https://simpleisbetterthancomplex.com/tips/2017/07/03/django-tip-20-working-with-multiple-settings-modules.html

I hope this helps!

-Jorge

On Mon, May 18, 2020 at 6:51 PM chaitanya orakala
mailto:chaitu.orak...@gmail.com>> wrote:

I tried that way, sir. but it's of no use. I don't know how to
resolve this issue. its been troubling me for 3 days now

On Mon, May 18, 2020 at 9:29 PM Mike Dewhirst
mailto:mi...@dewhirst.com.au>> wrote:

On 19/05/2020 11:10 am, chaitanya orakala wrote:
> I am using Python 2.7

It is possible you need a top line in the file like this ...

from __future__ import absolute_import

I haven't been following this thread so someone may have
mentioned that
already.


-- 
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/95afb956-98f8-6664-9107-d0935b75cf6c%40dewhirst.com.au.

-- 
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


Can Django (application itself) connect to MySQL via Kerberos/GSSAPI ticket instead of password?

2020-05-19 Thread Edward Rose
Hello - Does Django have any support for the web application itself being 
able to connect to MySQL using Kerberos Authentication / GSSAPI rather than 
a hard coded database user name and password?

I have searched around the web for a while and am still trying to find a 
way to get a Django web app itself to authenticate to a MySQL DB equipped 
with GSSAPI plugin via Kerberos. The Django app runs off Apache started in 
this way:

k5start -u user/server@domain -f /etc/krb5.keytab -- /usr/sbin/httpd 
-DFOREGROUND

The user/server user exists on the DB with adequate permissions. Moreover, 
on the command line this works and connects up fine:

k5start -u user/server@domain -f /etc/krb5.keytab -- mysql -u user/server

However, I've tried getting the web app to connect to the DB (the app 
itself, not worrying about the user authentication yet) about a million 
different ways. I verified the user running the web app is apache even when 
run started up the k5start way. Nonetheless any requests are met with this 
error:

(1105, 'Client GSSAPI error (major 851968, minor 0) : gss_init_sec_context - 
Unspecified GSS failure.  Minor code may provide more information. ')


The settings.py configuration for the database is as follows:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', 
'NAME': 'my_database',
'USER': 'user/server@domain',
#'PASSWORD' : '',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}



Server Specs:
Django version: 2.2.8
Python version: 3.6.8
OS version: RHEL 7.8 (Maipo)
MySQL version: 10.1.45-MariaDB MariaDB Server


I am thinking perhaps Django is just not designed to work this way? I did 
trace some of the code in the packages Django uses to connect to MySQL and 
it appears to be something along the lines of mysql_connect / the MySQL 
Connector C libraries or whatnot. And from what I saw a lot of the 
parameters the code uses following the MySQL website documentation but 
there was one parameter 'auth_plugin' or something like that, which did not 
seem to be implemented. Yet at the same time it would seem like getting 
Django to connect to the DB via kerberos would be a common problem? Again, 
this is a separate problem I'm trying to solve besides authenticating users 
to the website, rather I'm hoping to allow the app itself to authenticate 
to the database with kerb ticket, and had been hoping starting up apache in 
a kerberized way might let that happen. 

Any suggestions from people more Kerberos knowledgeable than I?

-- 
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/7b12fcab-37e1-4bc9-b6e5-0c73a4437540%40googlegroups.com.


Re: Media files and download url

2020-05-19 Thread Riska Kurniyanto Abdullah
https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html

You can used that modules and set the ACL.

You can jump here, in Vitor article :
https://simpleisbetterthancomplex.com/tutorial/2017/08/01/how-to-setup-amazon-s3-in-a-django-project.html
then
go to the chapter : Mixing public assets and private assets


This e-mail (including any attachments) is private and confidential and may
contain privileged material. If you have received this e-mail in error,
please notify the sender and delete it (including any
attachments) immediately. You must not copy, distribute, disclose or use
any of the information in it or any attachments.


On Thu, May 14, 2020 at 9:20 PM Parampal Singh 
wrote:

> More details please 😊
>
> On Tue, May 12, 2020, 12:52 AM Riska Kurniyanto Abdullah <
> alternative@gmail.com> wrote:
>
>> Amazon S3 have simple solution for that topic
>>
>>
>> On Tue, May 12, 2020 at 1:27 AM Parampal Singh <
>> parampalsingh...@gmail.com> wrote:
>>
>>> Access media vedio files only when user logged in
>>>
>>> Temporary file download url every time change
>>>
>>>
>>> Any suggestions on these topics
>>>
>>> --
>>> 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/e3df42b1-4dc8-478f-a25f-3315451f0852%40googlegroups.com
>>> .
>>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/ilYjagGe-UY/unsubscribe.
>> To unsubscribe from this group and all its topics, 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/CAG7yD2%2BWYKor2k8KRuq5peg1c3rPxRzpn6hoD4Ji8dfxhDi_Lw%40mail.gmail.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/CANYMdQLZSsNSLuTyXyTgakQiE0w59ojbfygxKSbBxTXkb_L7rw%40mail.gmail.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/CAG7yD2%2BYC4F5jOgKdQst6fBpQFRXXiwDMRJDZPuy4EquocZ0SA%40mail.gmail.com.


Re: Can Django (application itself) connect to MySQL via Kerberos/GSSAPI ticket instead of password?

2020-05-19 Thread Hella Nick
Mysql8.0以上的版本更改了加密规则,这可能需要你多研究一下遇到的问题。我记得需要修改Django框架中的一些源码。


在 2020年5月20日星期三 UTC+8上午9:37:33,Edward Rose写道:
>
> Hello - Does Django have any support for the web application itself being 
> able to connect to MySQL using Kerberos Authentication / GSSAPI rather than 
> a hard coded database user name and password?
>
> I have searched around the web for a while and am still trying to find a 
> way to get a Django web app itself to authenticate to a MySQL DB equipped 
> with GSSAPI plugin via Kerberos. The Django app runs off Apache started in 
> this way:
>
> k5start -u user/server@domain -f /etc/krb5.keytab -- /usr/sbin/httpd 
> -DFOREGROUND
>
> The user/server user exists on the DB with adequate permissions. Moreover, 
> on the command line this works and connects up fine:
>
> k5start -u user/server@domain -f /etc/krb5.keytab -- mysql -u user/server
>
> However, I've tried getting the web app to connect to the DB (the app 
> itself, not worrying about the user authentication yet) about a million 
> different ways. I verified the user running the web app is apache even when 
> run started up the k5start way. Nonetheless any requests are met with this 
> error:
>
> (1105, 'Client GSSAPI error (major 851968, minor 0) : gss_init_sec_context - 
> Unspecified GSS failure.  Minor code may provide more information. ')
>
>
> The settings.py configuration for the database is as follows:
>
> DATABASES = {
> 'default': {
> 'ENGINE': 'django.db.backends.mysql', 
> 'NAME': 'my_database',
> 'USER': 'user/server@domain',
> #'PASSWORD' : '',
> 'HOST': 'localhost', # Or an IP Address that your DB is hosted on
> 'PORT': '3306',
> }
> }
>
>
>
> Server Specs:
> Django version: 2.2.8
> Python version: 3.6.8
> OS version: RHEL 7.8 (Maipo)
> MySQL version: 10.1.45-MariaDB MariaDB Server
>
>
> I am thinking perhaps Django is just not designed to work this way? I did 
> trace some of the code in the packages Django uses to connect to MySQL and 
> it appears to be something along the lines of mysql_connect / the MySQL 
> Connector C libraries or whatnot. And from what I saw a lot of the 
> parameters the code uses following the MySQL website documentation but 
> there was one parameter 'auth_plugin' or something like that, which did not 
> seem to be implemented. Yet at the same time it would seem like getting 
> Django to connect to the DB via kerberos would be a common problem? Again, 
> this is a separate problem I'm trying to solve besides authenticating users 
> to the website, rather I'm hoping to allow the app itself to authenticate 
> to the database with kerb ticket, and had been hoping starting up apache in 
> a kerberized way might let that happen. 
>
> Any suggestions from people more Kerberos knowledgeable than I?
>
>

-- 
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/ceb2ce4c-7fa3-45fb-8f72-cff1329a3822%40googlegroups.com.


Re: PROBLEM WITH Multiple SETTINGS.PY FILE

2020-05-19 Thread Hella Nick
你帮我获得加拿大的工作移民签证,我就可以帮你解决问题。

在 2020年5月17日星期日 UTC+8上午4:51:45,chaitan写道:
>
> Hi, I am facing ModuleNotFoundError in my Django application. It got 
> configured with multiple settings files for production, Development & 
> Testing. 
> When I Try to run Python manage.py runserver --settings= settings_dev_sai. 
>
> This is My *Settings* File:
>
> import socket
>
> #import settings depending on the box we are on
> HOST = socket.gethostname()
> TPA_CODE = "Bridge"
> TPA_NAME = "Bridge Benefits System"
>
> #development
> if HOST == "BITS-DP-LAPTOP":
> from settings_dev import *
> TPA_NAME = "ICBA Benefit Services Ltd."
> TPA_CODE = 'ICBA' 
> #DFG bridge
> elif HOST == "dfginternal":
> from settings_dfg_ees import *
> TPA_NAME = "Dehoney Financial Group"
> TPA_CODE = 'DFG' 
> #test
> elif HOST == "DFGTEST02":
> from settings_staging import *
> elif HOST == "icbaweb":
> from settings_production_icba import *
> TPA_NAME = "ICBA Benefit Services Ltd."
> TPA_CODE = 'ICBA' 
> elif HOST == "meritweb":
> from settings_production_merit import *
> TPA_NAME = "Ontario Construction Industry Benefit Plan"
> TPA_CODE = 'MERIT' 
> elif HOST == "dfgweb" :
> from settings_production_dfg import *
> TPA_NAME = "Dehoney Financial Group"
> TPA_CODE = 'DFG' 
> elif HOST == "dev" or HOST == "j-ubu" :
> from settings_dev_baikal import *
> elif HOST == "jdev" :
> from settings_dev_juliab import *
> elif HOST == "Sai" :
> from settings_dev_sai import *
> elif HOST == "johnstonesweb" :
> from settings_production_johnstones import *
> TPA_NAME = "Johnstone's Benefits"
> TPA_CODE = 'JOHNSTONES' 
> elif HOST == "bridgedemo" :
> from settings_demo import *
> TPA_CODE = "Bridge"
> TPA_NAME = "Bridge Benefits System"
> else:
> raise ImportError("This server's hostname [" + HOST + "] does not have 
> a proper expanded settings file. Please configure one.")
> *
>
> This is my *settings_dev_sai*
>
> from settings_common import *
>
> DEBUG = True
> RUN_TYPE = RUN_DEV
>
> DATABASES = {
> 'default': {
> 'ENGINE': 'django.db.backends.postgresql_psycopg2',
> #'NAME': 'bridge_icba',
> 'NAME': 'bridge_js',
> #'NAME': 'bridge_dfg_internal',
> #'NAME': 'bridge_dfg',
> 'HOST': 'localhost',
> 'USER': 'django',
> 'PASSWORD': 'bridge_user',
> 'PORT': '',
> },
> }
>
> MEDIA_ROOT = 'C:/Users/DavidPiccione/Dropbox/Work - 
> Bridge/Projects/bridge/MEDIA/'
> MEDIA_URL = '/media/'
>
> EMAIL_HOST = 'smtp.gmail.com'
> EMAIL_PORT = 587
> EMAIL_HOST_USER = 'bridgeautoma...@gmail.com '
> EMAIL_HOST_PASSWORD = 'bridgeautomaticmessenger123'
> EMAIL_USE_TLS = True
> DEFAULT_FROM_EMAIL = 'bridgeautoma...@gmail.com '
>
>
> STATIC_ROOT = ''
> STATIC_URL = '/static/'
> STATICFILES_DIRS = ("C:/Users/DavidPiccione/Dropbox/Work - 
> Bridge/Projects/bridge/static",)
> STATIC_PATH = 'C:/Users/DavidPiccione/Dropbox/Work - 
> Bridge/Projects/bridge/static'
>
> TEMPLATES = [
> {
> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
> 'DIRS': ["C:/Users/DavidPiccione/Dropbox/Work - 
> Bridge/Projects/bridge/TEMPLATES",],
> 'APP_DIRS': False,
> 'OPTIONS': {
> 'context_processors': [
> 'django.contrib.auth.context_processors.auth',
> 'django.template.context_processors.debug',
> 'django.template.context_processors.i18n',
> 'django.template.context_processors.media',
> 'django.template.context_processors.static',
> 'django.template.context_processors.tz',
> 'django.template.context_processors.request',
> 'django.contrib.messages.context_processors.messages',
> 'bridge.context_processors.global_settings',],
> },
> },
> ]
>
>
> USE_ASSOCIATION_BANK_ACCOUNTS = True
>
>
> **
>
> This is *settings_common* file
>
> DMINS = ()
> BRIDGE_VERSION = "3.6.1 Build 202004.4" 
>
> MANAGERS = ADMINS
>
> TIME_ZONE = 'America/Vancouver'
> LANGUAGE_CODE = 'en-us'
> SITE_ID = 1
>
> USE_I18N = True
> USE_L10N = True
> USE_TZ = False
>
> # Make this unique and don't share it with anybody.
> SECRET_KEY ='removed for privacy reason'
> SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
>
> STATICFILES_FINDERS = (
> 'django.contrib.staticfiles.finders.FileSystemFinder',
> 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
> )
>
> MIDDLEWARE_CLASSES = (
> 'django.middleware.common.CommonMiddleware',
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.csrf.CsrfViewMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> 'django.contrib.messages.middleware.MessageMiddleware',
> 'bridge.request_access.Middleware',
> )
>
> ROOT_URLCONF 

Re: Can't Fix the No Reverse Error in Ajax

2020-05-19 Thread Hella Nick
button标签中的type属性设置为button,

Ahmed Khairy  于2020年5月20日周三 上午1:54写道:

> I am trying to use Ajax to submit a like button, I believe everything is
> in order but I keep getting django.urls.exceptions.NoReverseMatch: Reverse
> for 'like_post' with arguments '('',)' not found. 1 pattern(s) tried:
> ['score/like/(?P[0-9]+)$']
>
>
> I am not sure what is the reason. Need help to identify the error.
>
>
> Here is the view
>
>
> class PostDetailView(DetailView):
> model = Post
> template_name = "post_detail.html"
>
> def get_context_data(self, *args, **kwargs):
> context = super(PostDetailView, self).get_context_data()
> stuff = get_object_or_404(Post, id=self.kwargs['pk'])
> total_likes = stuff.total_likes()
> liked = False
> if stuff.likes.filter(id=self.request.user.id).exists():
> liked = True
> context["total_likes"] = total_likes
> context["liked"] = liked
> return context
>
>
> def LikeView(request, pk):
> # post = get_object_or_404(Post, id=request.POST.get('post_id'))
> post = get_object_or_404(Post, id=request.POST.get('id'))
> like = False
> if post.likes.filter(id=request.user.id).exists():
> post.likes.remove(request.user)
> like = False
> else:
> post.likes.add(request.user)
> like = True
> context["total_likes"] = total_likes
> context["liked"] = liked
>
> if request.is_ajax:
> html = render_to_string('like_section.html', context, request=
> request)
> return JsonResponse({'form': html})
>
> Here is the url.py updated
>
> urlpatterns = [
> path('user/', UserPostListView.as_view(), name=
> 'user-posts'),
> path('', PostListView.as_view(), name='score'),
> path('who_we_Are/', who_we_are, name='who_we_are'),
> path('/', PostDetailView.as_view(), name='post-detail'),
> path('like/', LikeView, name='like_post'),
> path('new/', PostCreateView.as_view(), name='post-create'),
> path('/update/', PostUpdateView.as_view(), name='post-update'
> ),
> path('/delete/', PostDeleteView.as_view(), name='post-delete')
> ]
>
> here is the template
>
> 
> {% csrf_token %}
>  Likes: {{total_likes}} 
> {% if user.is_authenticated %}
> {% if liked %}
>  'post_id' class= "btn btn-danger btn-sm"
> value="{{post.id}}"> Unlike 
> {% else %}
>  'post_id' class= "btn btn-primary btn-sm"
> value="{{post.id}}"> Like 
> {% endif  %}
> {% else %}
>  Login a> to Like 
> {% endif %}
> 
>
> here is the ajax
>
> https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";> >
>
> 
> $(document).ready(function(event){
> $(document).on.('click','#like', function(event){
> event.preventDefault();
> $var pk= $(this).attr('value');
> $.ajax({
> type:'POST',
> url:'{% url "score:like_post" post.pk %}',
> data:{'id': pk, 'csrfmiddlewaretoken':'{{csrf_token}}'
> },
> dataType:'json',
> success:function(response){
> $('#like-section').html(response['form'])
> console.log($('#like-section').html(response[
> 'form']));
> },
> error:function(rs, e){
> console.log(rs.responseText);
> },
> });
> });
> });
> 
>
>
> --
> 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/5aaa1274-dd6b-42bc-8a5e-bce4596ace98%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/CAHfGPEfgvvS1LMvF3FWM8Hb%3DbPoFVDVWM8anE1YwxN64KCviKA%40mail.gmail.com.


Re: Can't Fix the No Reverse Error in Ajax

2020-05-19 Thread Hella Nick
Django中的表单提交按钮不要使用submit属性,否则会触发get请求,或者发生错误。

Hella Nick  于2020年5月20日周三 上午11:09写道:

> button标签中的type属性设置为button,
>
> Ahmed Khairy  于2020年5月20日周三 上午1:54写道:
>
>> I am trying to use Ajax to submit a like button, I believe everything is
>> in order but I keep getting django.urls.exceptions.NoReverseMatch: Reverse
>> for 'like_post' with arguments '('',)' not found. 1 pattern(s) tried:
>> ['score/like/(?P[0-9]+)$']
>>
>>
>> I am not sure what is the reason. Need help to identify the error.
>>
>>
>> Here is the view
>>
>>
>> class PostDetailView(DetailView):
>> model = Post
>> template_name = "post_detail.html"
>>
>> def get_context_data(self, *args, **kwargs):
>> context = super(PostDetailView, self).get_context_data()
>> stuff = get_object_or_404(Post, id=self.kwargs['pk'])
>> total_likes = stuff.total_likes()
>> liked = False
>> if stuff.likes.filter(id=self.request.user.id).exists():
>> liked = True
>> context["total_likes"] = total_likes
>> context["liked"] = liked
>> return context
>>
>>
>> def LikeView(request, pk):
>> # post = get_object_or_404(Post, id=request.POST.get('post_id'))
>> post = get_object_or_404(Post, id=request.POST.get('id'))
>> like = False
>> if post.likes.filter(id=request.user.id).exists():
>> post.likes.remove(request.user)
>> like = False
>> else:
>> post.likes.add(request.user)
>> like = True
>> context["total_likes"] = total_likes
>> context["liked"] = liked
>>
>> if request.is_ajax:
>> html = render_to_string('like_section.html', context, request=
>> request)
>> return JsonResponse({'form': html})
>>
>> Here is the url.py updated
>>
>> urlpatterns = [
>> path('user/', UserPostListView.as_view(), name=
>> 'user-posts'),
>> path('', PostListView.as_view(), name='score'),
>> path('who_we_Are/', who_we_are, name='who_we_are'),
>> path('/', PostDetailView.as_view(), name='post-detail'),
>> path('like/', LikeView, name='like_post'),
>> path('new/', PostCreateView.as_view(), name='post-create'),
>> path('/update/', PostUpdateView.as_view(), name='post-update'
>> ),
>> path('/delete/', PostDeleteView.as_view(), name='post-delete'
>> )
>> ]
>>
>> here is the template
>>
>> 
>> {% csrf_token %}
>>  Likes: {{total_likes}} 
>> {% if user.is_authenticated %}
>> {% if liked %}
>> > 'post_id' class= "btn btn-danger btn-sm"
>> value="{{post.id}}"> Unlike 
>> {% else %}
>> > 'post_id' class= "btn btn-primary btn-sm"
>> value="{{post.id}}"> Like 
>> {% endif  %}
>> {% else %}
>> > > Login to Like 
>> {% endif %}
>> 
>>
>> here is the ajax
>>
>> https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";>> script>
>>
>>