Linking two separate django projects
I'm currently in the process of building my portfolio website. Although this site is mostly static I'm using django as the backend for it \(I have some plans to make it more backend heavy in the future\). I plan on making some small personal projects with django and then somehow linking them on my portfolio page.
My question is how can I link two separate django projects together? I dont want to buy a domain name and more server hosting for these small personal projects because I think thats a bit overkill and expensive. These projects are only examples of what I can do and serve as a placeholder until I get some real projects done.
I know you can create reuseable apps in django but I think it might get pretty messy trying to combine all these apps and their static files and databases into one app. Is this my best option? I don't mind hosting multiple apps on one VPS.
This is only going to be temporary, I'm hoping to get some real projects done which will then replace these personal ones.
Thanks guys
/r/django
https://redd.it/8o7t78
I'm currently in the process of building my portfolio website. Although this site is mostly static I'm using django as the backend for it \(I have some plans to make it more backend heavy in the future\). I plan on making some small personal projects with django and then somehow linking them on my portfolio page.
My question is how can I link two separate django projects together? I dont want to buy a domain name and more server hosting for these small personal projects because I think thats a bit overkill and expensive. These projects are only examples of what I can do and serve as a placeholder until I get some real projects done.
I know you can create reuseable apps in django but I think it might get pretty messy trying to combine all these apps and their static files and databases into one app. Is this my best option? I don't mind hosting multiple apps on one VPS.
This is only going to be temporary, I'm hoping to get some real projects done which will then replace these personal ones.
Thanks guys
/r/django
https://redd.it/8o7t78
reddit
r/django - Linking two separate django projects
1 votes and 0 so far on reddit
need some help with form creation
So I am trying to create a form on my site.
This form will take in 4 fields. 3 are textfields and one is a file field intended only for multiple picture uploads.
After doing some researching I decided that it would be best to create a model that would store what is gotten from this field? My main issue right now is 2 things
* validation of the inputs and saving the inputs
* printing out the pictures that were received from the uploads
I have looked at the django documentation but it doesnt make much sense to me, can anyone help me or point me to a repo somewhere else that has the pointers I need to be able to do what I want it to do? I'm a django noobie and lost on what I need to do next and unfortunately I find the django documentation, while vast in its knowledge, doesnt provide any working coding examples that I like to use to compare and contrast
My code below
views.py
from django.shortcuts import render, redirect
from django.http import HttpResponseRedirect
from documents.forms import ContactForm
from django.views.generic import TemplateView
def index(request):
print("constitution index")
return render(request, 'documents/constitution.html')
def policies(request):
print("policies index")
return render(request, 'documents/policies.html')
def photo_gallery(request):
if request.method == 'POST':
print("photo_gallery POST")
form = ContactForm(request.POST)
form.save()
title = form.cleaned_data['title']
additional_info = form.cleaned_data['additional_info']
print("additional_info=["+str(additional_info)+"]")
contact_info = form.cleaned_data['contact_info']
photos = request.FILES.getlist('pics_from_event')
if photos is not None:
for photo in photos:
print("photo=["+str(photo)+"]")
else:
print("no pictures detected")
else:
form = ContactForm()
args = {'form': form}
print("photo_gallery not POST")
return render(request, 'documents/photo_gallery.html', args)
def photos(request):
print("photo gallery index")
return render(request, 'documents/photo_gallery.html')
# Create your views here.
forms.py
from django import forms
from documents.models import Upload
class ContactForm(forms.ModelForm):
title = forms.CharField(required=True)
contact_info = forms.CharField(required=False)
additional_info = forms.CharField(required=False)
pics_from_event = forms.FileField(required=True,
widget=forms.ClearableFileInput(attrs={'multiple': True}))
class Meta:
model = Upload
fields = ('title', 'contact_info', 'additional_info', 'pics_from_event' )
def save(self, commit=True):
upload = super(ContactForm, self).save(commit=False)
upload.title = self.cleaned_data['title']
upload.contact_info = self.cleaned_data['contact_info']
upload.additional_info = self.cleaned_data['additional_info']
if commit:
upload.save()
return upload
models.py
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
def get_settings():
return {
'attachment_upload_to': getattr(
settings,
'USER_ATTACHMENT_UPLOAD_TO',
'UPLOAD_attachments/%Y/%m/%d/'
)
}
def get_attachment_save_path(instance, filename):
settings = get_settings()
path = settings['attachment_upload_to']
if '%' in path:
path = datetime.datetime.utcnow().strftime(path)
return os.path.join(
path,
filename,
)
class documentsPage(models.Model):
title=models.CharField(max_length=140)
body=models.TextField()
def __str__(self):
return self.title
# Create your models here.
class Upload(models.Model):
title = models.CharField(
_(u'title'),
max_length=255
)
contact_info = models.CharField(
_(u'title'),
max_length=255
)
additional_info = models.CharField(
_(u'title'),
max_length=255
)
message_id = models.CharField(
_(u'Message ID'),
max_length=255
)
class UploadAttachment(models.Model):
upload = models.ForeignKey(
Uplo
So I am trying to create a form on my site.
This form will take in 4 fields. 3 are textfields and one is a file field intended only for multiple picture uploads.
After doing some researching I decided that it would be best to create a model that would store what is gotten from this field? My main issue right now is 2 things
* validation of the inputs and saving the inputs
* printing out the pictures that were received from the uploads
I have looked at the django documentation but it doesnt make much sense to me, can anyone help me or point me to a repo somewhere else that has the pointers I need to be able to do what I want it to do? I'm a django noobie and lost on what I need to do next and unfortunately I find the django documentation, while vast in its knowledge, doesnt provide any working coding examples that I like to use to compare and contrast
My code below
views.py
from django.shortcuts import render, redirect
from django.http import HttpResponseRedirect
from documents.forms import ContactForm
from django.views.generic import TemplateView
def index(request):
print("constitution index")
return render(request, 'documents/constitution.html')
def policies(request):
print("policies index")
return render(request, 'documents/policies.html')
def photo_gallery(request):
if request.method == 'POST':
print("photo_gallery POST")
form = ContactForm(request.POST)
form.save()
title = form.cleaned_data['title']
additional_info = form.cleaned_data['additional_info']
print("additional_info=["+str(additional_info)+"]")
contact_info = form.cleaned_data['contact_info']
photos = request.FILES.getlist('pics_from_event')
if photos is not None:
for photo in photos:
print("photo=["+str(photo)+"]")
else:
print("no pictures detected")
else:
form = ContactForm()
args = {'form': form}
print("photo_gallery not POST")
return render(request, 'documents/photo_gallery.html', args)
def photos(request):
print("photo gallery index")
return render(request, 'documents/photo_gallery.html')
# Create your views here.
forms.py
from django import forms
from documents.models import Upload
class ContactForm(forms.ModelForm):
title = forms.CharField(required=True)
contact_info = forms.CharField(required=False)
additional_info = forms.CharField(required=False)
pics_from_event = forms.FileField(required=True,
widget=forms.ClearableFileInput(attrs={'multiple': True}))
class Meta:
model = Upload
fields = ('title', 'contact_info', 'additional_info', 'pics_from_event' )
def save(self, commit=True):
upload = super(ContactForm, self).save(commit=False)
upload.title = self.cleaned_data['title']
upload.contact_info = self.cleaned_data['contact_info']
upload.additional_info = self.cleaned_data['additional_info']
if commit:
upload.save()
return upload
models.py
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
def get_settings():
return {
'attachment_upload_to': getattr(
settings,
'USER_ATTACHMENT_UPLOAD_TO',
'UPLOAD_attachments/%Y/%m/%d/'
)
}
def get_attachment_save_path(instance, filename):
settings = get_settings()
path = settings['attachment_upload_to']
if '%' in path:
path = datetime.datetime.utcnow().strftime(path)
return os.path.join(
path,
filename,
)
class documentsPage(models.Model):
title=models.CharField(max_length=140)
body=models.TextField()
def __str__(self):
return self.title
# Create your models here.
class Upload(models.Model):
title = models.CharField(
_(u'title'),
max_length=255
)
contact_info = models.CharField(
_(u'title'),
max_length=255
)
additional_info = models.CharField(
_(u'title'),
max_length=255
)
message_id = models.CharField(
_(u'Message ID'),
max_length=255
)
class UploadAttachment(models.Model):
upload = models.ForeignKey(
Uplo
ad,
related_name='upload',
null=True,
blank=True,
verbose_name=_('upload'),
on_delete=models.CASCADE
)
document = models.FileField(
_(u'Document'),
upload_to=get_attachment_save_path,
)
/r/djangolearning
https://redd.it/8o7h66
related_name='upload',
null=True,
blank=True,
verbose_name=_('upload'),
on_delete=models.CASCADE
)
document = models.FileField(
_(u'Document'),
upload_to=get_attachment_save_path,
)
/r/djangolearning
https://redd.it/8o7h66
reddit
r/djangolearning - need some help with form creation
1 votes and 0 so far on reddit
Do you normally use string.format() or percentage (%) to format your Python strings?
There are two ways of string formatting in python and I've been consistently using the percentage (%) method until now:
"Today is %s." % datetime.now() # 2018-06-03 16:50:35.226194
"%d is a good number." % 5 # 5
I know this may not be very eloquent, but does the job well. One of the major irritants for me is the number to string conversion, I've faced that error so many times in the earlier days when I simply used to `"There are " + x + " mangoes."`. This works great in most other languages as they "auto-convert" the x from integer to string, but not python because of its "explicitness". But today, I learned of this new method of `string.format()` which does the same job, perhaps more eloquently:
"Today is {0}.".format(datetime.now()) # 2018-06-03 16:50:35.226194
"{0} is a good number.".format(5) # 5
The only problem I'd imagine would be when you have to deal with long floats:
f = 1.234535666
"this is a floating point number: {0}".format(f) # 1.234535666
Problem here is that it will output the entire float as it is without rounding, and here is where my percentage method has an edge!
"this is a floating point number: %.2f" % f # 1.23
/r/Python
https://redd.it/8o7yhi
There are two ways of string formatting in python and I've been consistently using the percentage (%) method until now:
"Today is %s." % datetime.now() # 2018-06-03 16:50:35.226194
"%d is a good number." % 5 # 5
I know this may not be very eloquent, but does the job well. One of the major irritants for me is the number to string conversion, I've faced that error so many times in the earlier days when I simply used to `"There are " + x + " mangoes."`. This works great in most other languages as they "auto-convert" the x from integer to string, but not python because of its "explicitness". But today, I learned of this new method of `string.format()` which does the same job, perhaps more eloquently:
"Today is {0}.".format(datetime.now()) # 2018-06-03 16:50:35.226194
"{0} is a good number.".format(5) # 5
The only problem I'd imagine would be when you have to deal with long floats:
f = 1.234535666
"this is a floating point number: {0}".format(f) # 1.234535666
Problem here is that it will output the entire float as it is without rounding, and here is where my percentage method has an edge!
"this is a floating point number: %.2f" % f # 1.23
/r/Python
https://redd.it/8o7yhi
reddit
Do you normally use string.format() or percentage (%)... • r/Python
There are two ways of string formatting in python and I've been consistently using the percentage (%) method until now: "Today is %s." %...
Need help in inputing scores from quiz into text files and creating a program to display the scores
I have created the quiz but just need a way to have every person doing the quiz complete it 3 times and save the scores on text files. There a total of 3 classes where I need a text file for each class. Finally I need a program where I can display the information of each class seperatley while choosing to display it in alphabetical order showing each students highest score,by the highest score in descending order and by the average score in descending order. I know this is alot to ask but I am currently just lost on how to do this.
The code https://imgur.com/a/qR54CAI
/r/Python
https://redd.it/8o8qbv
I have created the quiz but just need a way to have every person doing the quiz complete it 3 times and save the scores on text files. There a total of 3 classes where I need a text file for each class. Finally I need a program where I can display the information of each class seperatley while choosing to display it in alphabetical order showing each students highest score,by the highest score in descending order and by the average score in descending order. I know this is alot to ask but I am currently just lost on how to do this.
The code https://imgur.com/a/qR54CAI
/r/Python
https://redd.it/8o8qbv
[Book announcement] Building Multi Tenant Applications with Django - Details in comments
https://github.com/agiliq/building-multi-tenant-applications-with-django/
/r/django
https://redd.it/8o9l1g
https://github.com/agiliq/building-multi-tenant-applications-with-django/
/r/django
https://redd.it/8o9l1g
GitHub
GitHub - agiliq/building-multi-tenant-applications-with-django
Contribute to agiliq/building-multi-tenant-applications-with-django development by creating an account on GitHub.
The Google reCaptcha solver bot that I made in action.
https://youtu.be/YzjsXqnAO8w
/r/Python
https://redd.it/8o9k0s
https://youtu.be/YzjsXqnAO8w
/r/Python
https://redd.it/8o9k0s
YouTube
reCAPTCHA v2 Solver [Automated Python Bot]
Feel free to message me or comment with any questions.
Song: The Custodian of Records - 23 - Emo Step Show
Song: The Custodian of Records - 23 - Emo Step Show
Social Groups in Django
Let's say I have an 'articles' app. A user who belongs to 'Group A' publishes an article. This article can only be read by the members of 'Group A.' 'Group A' also has a superuser but his permissions are only valid for users in 'Group A.' How would I go about implementing this?
/r/django
https://redd.it/8o9ysg
Let's say I have an 'articles' app. A user who belongs to 'Group A' publishes an article. This article can only be read by the members of 'Group A.' 'Group A' also has a superuser but his permissions are only valid for users in 'Group A.' How would I go about implementing this?
/r/django
https://redd.it/8o9ysg
reddit
r/django - Social Groups in Django
2 votes and 1 so far on reddit
Super Beginner Python question.
Hi all,
I am currently programming some descriptive analytics on a CSV file.
I have imported using Pandas as far as I know.
My general aim; Create a bar chart of Location occurrence within the CSV file
The image below is as far as I have got but this is not all of the variables.
I am wondering if there is a way of importing the 'many' different locations as separate variables as I need to add 1 to each variable when the regex is matched against the CSV.
The CSV column is called; \(Some are abbreviated for ease as variables\)
**Borough**
>COL = 0
>
>Barnet = 0
>
>Bexley = 0
>
>BAD = 0
>
>Brent = 0
>
>Bromley = 0
>
>Camden = 0
>
>Croydon = 0
>
>Ealing = 0
>
>Enfield = 0
>
>Greenwich = 0
>
>Hackney = 0
>
>HAF = 0
>
>Haringey = 0
>
>Harrow = 0
>
>Havering = 0
>
>Hillingdon = 0
>
>Hounslow = 0
>
>Islington = 0
>
>KAC = 0
>
>KUT = 0
>
>Lambeth = 0
>
>Lewisham = 0
>
>Merton = 0
>
>Newham = 0
>
>Redbridge = 0
>
>RUT = 0
>
>Southwark = 0
>
>Sutton = 0
>
>TowerHamlets = 0
>
>WalthamForest = 0
>
>Wandsworth = 0
>
>Westminster = 0
>
>OuterBorough = 0
>
>InnerBorough = 0
Here is my current code with the output of the image below:
#Start of Imports
import csv
import sys
import numpy as np
import pandas as pd
import re
import matplotlib.pyplot as plt
#End of Imports
#Start of Declarations
COL = 0
Barnet = 0
Bexley = 0
BAD = 0
Brent = 0
Bromley = 0
Camden = 0
Croydon = 0
Ealing = 0
#This is as far as I got when I thought something was wrong?
Enfield = 0
Greenwich = 0
Hackney = 0
HAF = 0
Haringey = 0
Harrow = 0
Havering = 0
Hillingdon = 0
Hounslow = 0
Islington = 0
KAC = 0
KUT = 0
Lambeth = 0
Lewisham = 0
Merton = 0
Newham = 0
Redbridge = 0
RUT = 0
Southwark = 0
Sutton = 0
TowerHamlets = 0
WalthamForest = 0
Wandsworth = 0
Westminster = 0
OuterBorough = 0
InnerBorough = 0
#End of Declarations
#Starts reading 'csv file'
csv = pd.read_csv ('land-area-population-density-london.csv') #Not sure what this does, index_col=3)
#Start of IF Statement
csva = np.array(csv)
for column in np.arange(0, csva.shape[0]):
if re.match(r"Barnet", str(csva[column][2])) is not None:
Barnet = Barnet + 1
elif re.match(r"Bexley", str(csva[column][2])) is not None:
Bexley = Bexley + 1
elif re.match(r"City of London", str(csva[column][2])) is not None:
COL = COL + 1
elif re.match(r"Barking and Dagenham", str(csva[column][2])) is not None:
BAD = BAD + 1
elif re.match(r"Brent", str(csva[column][2])) is not None:
Brent = Brent + 1
elif re.match(r"Bromley", str(csva[column][2])) is not None:
Bromley = Bromley + 1
elif re.match(r"Camden", str(csva[column][2])) is not None:
Camden = Camden + 1
elif re.match(r"Croydon", str(csva[column][2])) is not None:
Croydon = Croydon + 1
elif re.match(r"Ealing", str(csva[column][2])) is not None:
Ealing = Ealing + 1
#End of IF Statement
#Start of graph fields
#Below: Places is the labels for the placesvar
places = ('Barnet', 'Bexley', 'City of London', 'Barking and Dagenham', 'Brent', 'Bromley', 'Camden', 'Croydon', 'Ealing')
#Below: placesvar the actual 'places' pulled from CSV
placesvar = [Barnet, Bexley, COL, BAD, Brent, Bromley, Camden, Croydon, Ealing]
#Y Positioning numpy.arange (Again no idea what this does) length 'places pulled from csv'
y_pos = np.arange(len(placesvar))
#End of graph fields
#Start of Graph positions and Names
plt.bar(y_pos, placesvar, align='center')
plt.xticks(y_pos, places, rot
Hi all,
I am currently programming some descriptive analytics on a CSV file.
I have imported using Pandas as far as I know.
My general aim; Create a bar chart of Location occurrence within the CSV file
The image below is as far as I have got but this is not all of the variables.
I am wondering if there is a way of importing the 'many' different locations as separate variables as I need to add 1 to each variable when the regex is matched against the CSV.
The CSV column is called; \(Some are abbreviated for ease as variables\)
**Borough**
>COL = 0
>
>Barnet = 0
>
>Bexley = 0
>
>BAD = 0
>
>Brent = 0
>
>Bromley = 0
>
>Camden = 0
>
>Croydon = 0
>
>Ealing = 0
>
>Enfield = 0
>
>Greenwich = 0
>
>Hackney = 0
>
>HAF = 0
>
>Haringey = 0
>
>Harrow = 0
>
>Havering = 0
>
>Hillingdon = 0
>
>Hounslow = 0
>
>Islington = 0
>
>KAC = 0
>
>KUT = 0
>
>Lambeth = 0
>
>Lewisham = 0
>
>Merton = 0
>
>Newham = 0
>
>Redbridge = 0
>
>RUT = 0
>
>Southwark = 0
>
>Sutton = 0
>
>TowerHamlets = 0
>
>WalthamForest = 0
>
>Wandsworth = 0
>
>Westminster = 0
>
>OuterBorough = 0
>
>InnerBorough = 0
Here is my current code with the output of the image below:
#Start of Imports
import csv
import sys
import numpy as np
import pandas as pd
import re
import matplotlib.pyplot as plt
#End of Imports
#Start of Declarations
COL = 0
Barnet = 0
Bexley = 0
BAD = 0
Brent = 0
Bromley = 0
Camden = 0
Croydon = 0
Ealing = 0
#This is as far as I got when I thought something was wrong?
Enfield = 0
Greenwich = 0
Hackney = 0
HAF = 0
Haringey = 0
Harrow = 0
Havering = 0
Hillingdon = 0
Hounslow = 0
Islington = 0
KAC = 0
KUT = 0
Lambeth = 0
Lewisham = 0
Merton = 0
Newham = 0
Redbridge = 0
RUT = 0
Southwark = 0
Sutton = 0
TowerHamlets = 0
WalthamForest = 0
Wandsworth = 0
Westminster = 0
OuterBorough = 0
InnerBorough = 0
#End of Declarations
#Starts reading 'csv file'
csv = pd.read_csv ('land-area-population-density-london.csv') #Not sure what this does, index_col=3)
#Start of IF Statement
csva = np.array(csv)
for column in np.arange(0, csva.shape[0]):
if re.match(r"Barnet", str(csva[column][2])) is not None:
Barnet = Barnet + 1
elif re.match(r"Bexley", str(csva[column][2])) is not None:
Bexley = Bexley + 1
elif re.match(r"City of London", str(csva[column][2])) is not None:
COL = COL + 1
elif re.match(r"Barking and Dagenham", str(csva[column][2])) is not None:
BAD = BAD + 1
elif re.match(r"Brent", str(csva[column][2])) is not None:
Brent = Brent + 1
elif re.match(r"Bromley", str(csva[column][2])) is not None:
Bromley = Bromley + 1
elif re.match(r"Camden", str(csva[column][2])) is not None:
Camden = Camden + 1
elif re.match(r"Croydon", str(csva[column][2])) is not None:
Croydon = Croydon + 1
elif re.match(r"Ealing", str(csva[column][2])) is not None:
Ealing = Ealing + 1
#End of IF Statement
#Start of graph fields
#Below: Places is the labels for the placesvar
places = ('Barnet', 'Bexley', 'City of London', 'Barking and Dagenham', 'Brent', 'Bromley', 'Camden', 'Croydon', 'Ealing')
#Below: placesvar the actual 'places' pulled from CSV
placesvar = [Barnet, Bexley, COL, BAD, Brent, Bromley, Camden, Croydon, Ealing]
#Y Positioning numpy.arange (Again no idea what this does) length 'places pulled from csv'
y_pos = np.arange(len(placesvar))
#End of graph fields
#Start of Graph positions and Names
plt.bar(y_pos, placesvar, align='center')
plt.xticks(y_pos, places, rot
ation=60)
plt.ylabel('No. of occurance')
plt.xlabel('Locations')
plt.title('Occurance of Locations')
#plt.savefig('file.png')(Commented out for testing)
#End of Graph positions and Names
plt.show()
https://i.redd.it/n311chii2u111.png
/r/Python
https://redd.it/8oat6s
plt.ylabel('No. of occurance')
plt.xlabel('Locations')
plt.title('Occurance of Locations')
#plt.savefig('file.png')(Commented out for testing)
#End of Graph positions and Names
plt.show()
https://i.redd.it/n311chii2u111.png
/r/Python
https://redd.it/8oat6s
DRF+Django
Hi there,
So we're fairly new to Django and wish to make a backend using it for a RN app. The DB needs to be Postgres. Therefore my question was how does DRF/Django sit in this? Does Django get installed/used for the migrations as a prerequisite for DRF? As the client will then be querying the DB through DRF as the API.
/r/django
https://redd.it/8obdfb
Hi there,
So we're fairly new to Django and wish to make a backend using it for a RN app. The DB needs to be Postgres. Therefore my question was how does DRF/Django sit in this? Does Django get installed/used for the migrations as a prerequisite for DRF? As the client will then be querying the DB through DRF as the API.
/r/django
https://redd.it/8obdfb
reddit
r/django - DRF+Django
1 votes and 3 so far on reddit
Moving a locally hosted Flask App to another computer
I have a flask app that is saved on my computer and if I want to save it in a zip archive, then move it to another computer, using USB, can I still be able to run it standalone, or does the other PC need Python installed?
I'm using MySQL database and a virtual environment so I know I need some kind of a local server (like WAMP) to run it, but I'm not so sure about Python and it's dependencies. Are they standalone in the Virtual Environment or are they still dependend on the root Python files?
I'm asking this because I need to show the project in my school but don't want to host it on the web just yet.
/r/flask
https://redd.it/8obuj1
I have a flask app that is saved on my computer and if I want to save it in a zip archive, then move it to another computer, using USB, can I still be able to run it standalone, or does the other PC need Python installed?
I'm using MySQL database and a virtual environment so I know I need some kind of a local server (like WAMP) to run it, but I'm not so sure about Python and it's dependencies. Are they standalone in the Virtual Environment or are they still dependend on the root Python files?
I'm asking this because I need to show the project in my school but don't want to host it on the web just yet.
/r/flask
https://redd.it/8obuj1
reddit
r/flask - Moving a locally hosted Flask App to another computer
3 votes and 3 so far on reddit
i regexed all the commands from the very book i'm learning, for using as a personal cheat sheet [i am learning please dont judge :) ]
/r/Python
https://redd.it/8obvye
/r/Python
https://redd.it/8obvye
Best (fastest) algorithm to do this task ?
I'm creating a spell checker \(not for English\). For that I need to generate permutation for each word.
Lets assume the word is **jumbo** . And I have a dictionary with permutations stored.
dict = {
'u' : [ 'e','o' ],
'm' : [ 'n' ],
'o' : ['u']
}
From this I need to create all instances of the word with replacing the letter which is the key of the dictionary with the words of the values of each key. As an example, for **jumbo** according to *dict* dictionary there can be permutations like **jembo, jombo, janbo, jambu, jenbo, jonbo, jembu, jombu, janbu, jenbu, jonbu** . So, how can I generate all these combinations and generate all these permutation words ? I'm pretty sure I can do this with some nested loops. But what is the most efficient way ?
/r/Python
https://redd.it/8od6yd
I'm creating a spell checker \(not for English\). For that I need to generate permutation for each word.
Lets assume the word is **jumbo** . And I have a dictionary with permutations stored.
dict = {
'u' : [ 'e','o' ],
'm' : [ 'n' ],
'o' : ['u']
}
From this I need to create all instances of the word with replacing the letter which is the key of the dictionary with the words of the values of each key. As an example, for **jumbo** according to *dict* dictionary there can be permutations like **jembo, jombo, janbo, jambu, jenbo, jonbo, jembu, jombu, janbu, jenbu, jonbu** . So, how can I generate all these combinations and generate all these permutation words ? I'm pretty sure I can do this with some nested loops. But what is the most efficient way ?
/r/Python
https://redd.it/8od6yd
reddit
Best (fastest) algorithm to do this task ? • r/Python
I'm creating a spell checker \(not for English\). For that I need to generate permutation for each word. Lets assume the word is **jumbo** . And...
Django & JSONField & SqlLite - '
I have no idea where to ask this so I am starting here.
I am trying to write a django application \(my first\). In so doing, I am using a SQLite database. I have some data stored in JSON into a JSON Field:
`class Data(models.Model):`
`data = JSONField()`
the data stored in the data base in the data field is text like this:
`[`
`{`
`"datetime": "2018-05-31T00:00:00.000Z",`
`"value": 90`
`}`
`]`
in the HTML, I have at the end of the document:
`<script>`
`{% for data in datas %}`
`var x{{` [`data.id`](https://board.id) `}} = {{` [`data.data`](https://board.data) `}};`
`{% endfor %}`
`</script>`
but instead of creating var x1 with some json in it, I get:
var x1 = \[{AMPERSAND#39datetimeAMPERSAND#39: AMPERSAND#392018\-05\-31T00:00:00.000ZAMPERSAND#39, AMPERSAND#39valueAMPERSAND#39: 90}\]
Where you replace AMPERSAND with & because &# 39 doesn't show up right here.
All of the original double quotes in the database are replaced with ', which actually the ascii code for apostraphe. Do you guys have any tips for how I can have json in the database and get it out through django?
/r/django
https://redd.it/8oefeu
I have no idea where to ask this so I am starting here.
I am trying to write a django application \(my first\). In so doing, I am using a SQLite database. I have some data stored in JSON into a JSON Field:
`class Data(models.Model):`
`data = JSONField()`
the data stored in the data base in the data field is text like this:
`[`
`{`
`"datetime": "2018-05-31T00:00:00.000Z",`
`"value": 90`
`}`
`]`
in the HTML, I have at the end of the document:
`<script>`
`{% for data in datas %}`
`var x{{` [`data.id`](https://board.id) `}} = {{` [`data.data`](https://board.data) `}};`
`{% endfor %}`
`</script>`
but instead of creating var x1 with some json in it, I get:
var x1 = \[{AMPERSAND#39datetimeAMPERSAND#39: AMPERSAND#392018\-05\-31T00:00:00.000ZAMPERSAND#39, AMPERSAND#39valueAMPERSAND#39: 90}\]
Where you replace AMPERSAND with & because &# 39 doesn't show up right here.
All of the original double quotes in the database are replaced with ', which actually the ascii code for apostraphe. Do you guys have any tips for how I can have json in the database and get it out through django?
/r/django
https://redd.it/8oefeu
CollectID
board.id Is For Sale - CollectID
Domain name Board.id embodies a sense of authority, creativity, and identity. It conveys a strong message of leadership in the boardroom, suggesting a platform for innovative ideas and strategic decision-making. The word "Board" can be interpreted in multiple…
Concurrency issue? Standalone python script sharing settings.py and ORM with django server has unreliable view of DB objects?
I'm having a strange problem that is difficult to reproduce (everything worked 2 days ago but some time between then and now no longer does--with no changes in the interim!)
I have a django server program which we are running via gunicorn with multiple worker subprocesses and a separate small REST webservice which shares the settings.py of the server program and acts on the same DB objects. The code for this server program is roughly as follows:
# my app's models.py
class TestConfig(models.Model):
## various attributes
class Test(models.Model):
## some attributes
def startTest(self):
return TestExecution.objects.create(test=self)
class TestExecution(models.Model):
test = models.ForeignKey(
Test,
on_delete=models.CASCADE
)
config = models.ForeignKey(
TestConfig,
on_delete=models.CASCADE,
null=True
)
# excerpt from a post() method in my app's views.py
test = Test.objects.get(test_id)
if config_form.is_valid():
config = config_form.save()
config_id = config.id
test_exe = test.startTest()
test_exe.config = config
test_exe.save()
webservice_response = requests.get(
'http://{}:{}/rest/add_to_queue/{}'.format(
webservice_ip, webservice_port, test_exe.id))
The other program (small REST webservice) sharing the same settings.py as the django server program looks as follows:
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
import django
django.setup()
# the REST endpoint referenced from the django server program
@app.route('/rest/add_to_queue/<test_exe_object_id>/')
@app.route('/rest/add_to_queue/<test_exe_object_id>')
def add_to_queue(test_exe_object_id):
from myapp.models import TestExecution
try:
exe_object = TestExecution.objects.get(pk=int(test_exe_object_id))
# for completeness the database section of my settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test_db',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'localhost',
'PORT': '3306',
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
},
}
}
As I said, this was working fine a few days ago, then when I tried again today I was getting a DoesNotExist in the second program when trying to "get()" the TestExecution object using its 'id'.
Does anyone have experience with this or a similar issue?
/r/django
https://redd.it/8o9b8c
I'm having a strange problem that is difficult to reproduce (everything worked 2 days ago but some time between then and now no longer does--with no changes in the interim!)
I have a django server program which we are running via gunicorn with multiple worker subprocesses and a separate small REST webservice which shares the settings.py of the server program and acts on the same DB objects. The code for this server program is roughly as follows:
# my app's models.py
class TestConfig(models.Model):
## various attributes
class Test(models.Model):
## some attributes
def startTest(self):
return TestExecution.objects.create(test=self)
class TestExecution(models.Model):
test = models.ForeignKey(
Test,
on_delete=models.CASCADE
)
config = models.ForeignKey(
TestConfig,
on_delete=models.CASCADE,
null=True
)
# excerpt from a post() method in my app's views.py
test = Test.objects.get(test_id)
if config_form.is_valid():
config = config_form.save()
config_id = config.id
test_exe = test.startTest()
test_exe.config = config
test_exe.save()
webservice_response = requests.get(
'http://{}:{}/rest/add_to_queue/{}'.format(
webservice_ip, webservice_port, test_exe.id))
The other program (small REST webservice) sharing the same settings.py as the django server program looks as follows:
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
import django
django.setup()
# the REST endpoint referenced from the django server program
@app.route('/rest/add_to_queue/<test_exe_object_id>/')
@app.route('/rest/add_to_queue/<test_exe_object_id>')
def add_to_queue(test_exe_object_id):
from myapp.models import TestExecution
try:
exe_object = TestExecution.objects.get(pk=int(test_exe_object_id))
# for completeness the database section of my settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test_db',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'localhost',
'PORT': '3306',
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
},
}
}
As I said, this was working fine a few days ago, then when I tried again today I was getting a DoesNotExist in the second program when trying to "get()" the TestExecution object using its 'id'.
Does anyone have experience with this or a similar issue?
/r/django
https://redd.it/8o9b8c
reddit
r/django - Concurrency issue? Standalone python script sharing settings.py and ORM with django server has unreliable view of DB…
0 votes and 4 so far on reddit
Question about AWS and hosting a subdomain running flask next to a wordpress site on EC2
Is it really just as easy as following \[this\]\([https://www.brianshim.com/webtricks/host\-multiple\-sites\-amazon\-ec2/](https://www.brianshim.com/webtricks/host-multiple-sites-amazon-ec2/)\) tutorial and then building the app in the documentRoot directory dictated in the httpd.conf?
Any insight would be apppriciated.
I just want to be able to put \(possibly a few\) flask apps next to my wordpress blog. For example wordpress blog would be at spacebucketfu.com and the flask app would be app.spacebucketfu.com
/r/flask
https://redd.it/8oebsp
Is it really just as easy as following \[this\]\([https://www.brianshim.com/webtricks/host\-multiple\-sites\-amazon\-ec2/](https://www.brianshim.com/webtricks/host-multiple-sites-amazon-ec2/)\) tutorial and then building the app in the documentRoot directory dictated in the httpd.conf?
Any insight would be apppriciated.
I just want to be able to put \(possibly a few\) flask apps next to my wordpress blog. For example wordpress blog would be at spacebucketfu.com and the flask app would be app.spacebucketfu.com
/r/flask
https://redd.it/8oebsp
How can I read a client's IP address in a Jupyter Notebook?
Hello,
Is it possible to read an IP address in a Notebook?
I have multiple people connecting to a Notebook and I need to store their IP addresses.
I can see them in the Jupyter log file, but is there anyway I can use Python code to get the IP address of whoever is running the Notebook?
Each client connection needs to have a folder created with a name based on his or her IP address to store Excel processing output.
/r/IPython
https://redd.it/8oeros
Hello,
Is it possible to read an IP address in a Notebook?
I have multiple people connecting to a Notebook and I need to store their IP addresses.
I can see them in the Jupyter log file, but is there anyway I can use Python code to get the IP address of whoever is running the Notebook?
Each client connection needs to have a folder created with a name based on his or her IP address to store Excel processing output.
/r/IPython
https://redd.it/8oeros
reddit
r/IPython - How can I read a client's IP address in a Jupyter Notebook?
2 votes and 0 so far on reddit
The Problem With Your Dockerized Django Development Workflow
https://vsupalov.com/problem-django-development-workflow/
/r/django
https://redd.it/8og9fe
https://vsupalov.com/problem-django-development-workflow/
/r/django
https://redd.it/8og9fe
vsupalov.com
The Problem With Your Dockerized Django Development Workflow