Logging in a flask app
So I am running a flask app that has a lot of logging. Currently the log level is set to warning. But in the event of some issue, I'd would like to see the lower level debug logs.
Is restarting the app with the log level set to debug, the only way to do this? I'd need the error to happen again in this case. How is this done on production apps? Or do they set the log level to debug right from the start?
/r/flask
https://redd.it/13fwr6t
So I am running a flask app that has a lot of logging. Currently the log level is set to warning. But in the event of some issue, I'd would like to see the lower level debug logs.
Is restarting the app with the log level set to debug, the only way to do this? I'd need the error to happen again in this case. How is this done on production apps? Or do they set the log level to debug right from the start?
/r/flask
https://redd.it/13fwr6t
Reddit
r/flask on Reddit: Logging in a flask app
Posted by u/grchelp2018 - No votes and 2 comments
When using a filefield with WTForms, is the file fully uploaded to the server to validate file format?
I noticed it took more time when I submitted a larger file with invalid file format, for the page to reload with errors. Does the server receive the full file? If it does not receive the file, then how does the server know the file type?
TL;DR: Does a large file with invalid file type submitted in a WTForms filefield put load on the server?
/r/flask
https://redd.it/13frdsz
I noticed it took more time when I submitted a larger file with invalid file format, for the page to reload with errors. Does the server receive the full file? If it does not receive the file, then how does the server know the file type?
TL;DR: Does a large file with invalid file type submitted in a WTForms filefield put load on the server?
/r/flask
https://redd.it/13frdsz
Reddit
r/flask on Reddit: When using a filefield with WTForms, is the file fully uploaded to the server to validate file format?
Posted by u/remidentity - 1 vote and 1 comment
Foreign key option
I am making an app for a BJJ tournament. I have a form to catch competitors' registration like name, weight, and rank. After that, the admin will create however many groups for competition as needed. Each competitor can only be in 1 group.
Models.py
class Group1(models.Model):
grouplabel = models.CharField(maxlength=20, unique=True)
point = models.IntegerField(default=0)
class Competitors(models.Model):
flname = models.CharField(maxlength=255)
Weight = models.IntegerField(validators=[MinValueValidator(50), MaxValueValidator(300)])
rank = models.CharField(maxlength=255)
Group1 = models.ForeignKey(Group1, blank=True, null=True, ondelete=models.CASCADE, tofield='grouplabel')
[Admin.py](https://Admin.py)
​
class MemberAdmin(admin.ModelAdmin):
listdisplay = ("flname", "Weight", "rank", "Group1")
admin.site.unregister(Competitors)
admin.site.register(Competitors, MemberAdmin)
def str(self):
return f"{self.flname} {self.Weight}"
class MemberAdmin(admin.ModelAdmin):
listdisplay = ("grouplabel","point")
admin.site.unregister(Group1)
admin.site.register(Group1, MemberAdmin)
​
Here, we can
/r/djangolearning
[https://redd.it/13fun0n
I am making an app for a BJJ tournament. I have a form to catch competitors' registration like name, weight, and rank. After that, the admin will create however many groups for competition as needed. Each competitor can only be in 1 group.
Models.py
class Group1(models.Model):
grouplabel = models.CharField(maxlength=20, unique=True)
point = models.IntegerField(default=0)
class Competitors(models.Model):
flname = models.CharField(maxlength=255)
Weight = models.IntegerField(validators=[MinValueValidator(50), MaxValueValidator(300)])
rank = models.CharField(maxlength=255)
Group1 = models.ForeignKey(Group1, blank=True, null=True, ondelete=models.CASCADE, tofield='grouplabel')
[Admin.py](https://Admin.py)
​
class MemberAdmin(admin.ModelAdmin):
listdisplay = ("flname", "Weight", "rank", "Group1")
admin.site.unregister(Competitors)
admin.site.register(Competitors, MemberAdmin)
def str(self):
return f"{self.flname} {self.Weight}"
class MemberAdmin(admin.ModelAdmin):
listdisplay = ("grouplabel","point")
admin.site.unregister(Group1)
admin.site.register(Group1, MemberAdmin)
​
Here, we can
/r/djangolearning
[https://redd.it/13fun0n
Flask: Uploading pdfs to google drive using its API
for file in files:
filemetadata = {
'name' : securefilename(file.filename),
'parents' : folder_id
}
#f = io.BytesIO(file)
media = MediaFileUpload(file, mimetype = 'application/pdf')
drive.service.files().create(
body = filemetadata,
mediabody = media,
fields = 'id'
).execute()
So here's the part that I can't figure out. What is basically happening is that I have a form that takes in a list of pdf files (max 5 mb for each of those files) but what I can't figure out is how to upload those files to the google drive folder. I
/r/flask
https://redd.it/13gcndv
for file in files:
filemetadata = {
'name' : securefilename(file.filename),
'parents' : folder_id
}
#f = io.BytesIO(file)
media = MediaFileUpload(file, mimetype = 'application/pdf')
drive.service.files().create(
body = filemetadata,
mediabody = media,
fields = 'id'
).execute()
So here's the part that I can't figure out. What is basically happening is that I have a form that takes in a list of pdf files (max 5 mb for each of those files) but what I can't figure out is how to upload those files to the google drive folder. I
/r/flask
https://redd.it/13gcndv
Reddit
r/flask on Reddit: Flask: Uploading pdfs to google drive using its API
Posted by u/Seandara - 3 votes and 2 comments
Saturday Daily Thread: Resource Request and Sharing! Daily Thread
Found a neat resource related to Python over the past week? Looking for a resource to explain a certain topic?
Use this thread to chat about and share Python resources!
/r/Python
https://redd.it/13g1e22
Found a neat resource related to Python over the past week? Looking for a resource to explain a certain topic?
Use this thread to chat about and share Python resources!
/r/Python
https://redd.it/13g1e22
Reddit
r/Python on Reddit: Saturday Daily Thread: Resource Request and Sharing! Daily Thread
Posted by u/Im__Joseph - 9 votes and 2 comments
Do You Use Singletons?
I work on a monolith that needs to maintain many connections (SQL ODBC, HTTP, Redis, etc...) and I find myself worrying about connection management often. The monolith also has much of its functionality in a gunicorn/uvicorn/starlette server.
I often find myself wondering if I should implement singleton connection management classes for many of these connections. I'm aware that they don't work across multiple gunicorn workers, but at least I know there's only one aiomysql pool per worker, for example. Does anyone use singletons for this purpose, or is there a better design pattern that I'm not using?
/r/Python
https://redd.it/13g4ml1
I work on a monolith that needs to maintain many connections (SQL ODBC, HTTP, Redis, etc...) and I find myself worrying about connection management often. The monolith also has much of its functionality in a gunicorn/uvicorn/starlette server.
I often find myself wondering if I should implement singleton connection management classes for many of these connections. I'm aware that they don't work across multiple gunicorn workers, but at least I know there's only one aiomysql pool per worker, for example. Does anyone use singletons for this purpose, or is there a better design pattern that I'm not using?
/r/Python
https://redd.it/13g4ml1
Reddit
r/Python on Reddit: Do You Use Singletons?
Posted by u/Mubs - 111 votes and 67 comments
Generate Django templates with JS
https://github.com/LazerRaptor/django-template-gen/
I've been working on a Rollup.js plugin on the last few weekends that would generate Django templates from JS modules. It utilizes Rollup hooks that give access to source code (as a string) and AST, which makes it possible to pick certain bits of code. In this case, I needed to get
This is just an example project so far. The end goal is to bring the DX of node.js frontend libraries to the Django's ecosystem. For me, the functionality of Alpine.js and HTMX is great, but the DX is the biggest problem. I can't help but create a mess using them. There are projects like django-components and slippers that help to some extent. But I believe there is more potential for DX improvements if we move all our frontend work in node.js environment.
I'd appreciate if you had a quick look at the project's readme and shared your thoughts.
/r/django
https://redd.it/13gj12x
https://github.com/LazerRaptor/django-template-gen/
I've been working on a Rollup.js plugin on the last few weekends that would generate Django templates from JS modules. It utilizes Rollup hooks that give access to source code (as a string) and AST, which makes it possible to pick certain bits of code. In this case, I needed to get
render() method's return value, which is hyperscript that can be transpiled into HTML. The plugin lives here.This is just an example project so far. The end goal is to bring the DX of node.js frontend libraries to the Django's ecosystem. For me, the functionality of Alpine.js and HTMX is great, but the DX is the biggest problem. I can't help but create a mess using them. There are projects like django-components and slippers that help to some extent. But I believe there is more potential for DX improvements if we move all our frontend work in node.js environment.
I'd appreciate if you had a quick look at the project's readme and shared your thoughts.
/r/django
https://redd.it/13gj12x
GitHub
GitHub - LazerRaptor/django-template-gen: Generate Django templates in a Node.js environment
Generate Django templates in a Node.js environment - GitHub - LazerRaptor/django-template-gen: Generate Django templates in a Node.js environment
P New tokenization method improves LLM performance & context-length by 25%+
I've been working on this new tokenization method to optimally represent text with fewer tokens than current methods. It's MIT licensed.
Code at Github.
Test it out.
The general-english-65535 vocabulary, and the code versions are already complete. The general-english-32000 should be finished within a few hours. Then I'm going test a non-greedy version which should do even better.
Intro from README:
tokenmonster is a novel approach to tokenization with broad-ranging use potential, but its primary motivation is to increase the inference speed and context-length of large language models by choosing better tokens. By selecting more optimal tokens, text can be represented with 20-30% less tokens compared to other modern tokenizing methods, increasing the speed of inference, training and the length of text by 20-30%. The code-optimized tokenizers do even better, see it for yourself.
I also believe that tokenmonster vocabularies will improve the comprehension of Large Language Models. For more details see How and Why.
## Features
Longer text generation at faster speed
Determines the optimal token combination for a greedy tokenizer (non-greedy support coming)
Successfully identifies common phrases and figures of speech
Works with all languages and formats, even binary
Quickly skims over HTML tags, sequential spaces, tabs, etc. without wasting context
Does not require normalization
/r/MachineLearning
https://redd.it/13gdfw0
I've been working on this new tokenization method to optimally represent text with fewer tokens than current methods. It's MIT licensed.
Code at Github.
Test it out.
The general-english-65535 vocabulary, and the code versions are already complete. The general-english-32000 should be finished within a few hours. Then I'm going test a non-greedy version which should do even better.
Intro from README:
tokenmonster is a novel approach to tokenization with broad-ranging use potential, but its primary motivation is to increase the inference speed and context-length of large language models by choosing better tokens. By selecting more optimal tokens, text can be represented with 20-30% less tokens compared to other modern tokenizing methods, increasing the speed of inference, training and the length of text by 20-30%. The code-optimized tokenizers do even better, see it for yourself.
I also believe that tokenmonster vocabularies will improve the comprehension of Large Language Models. For more details see How and Why.
## Features
Longer text generation at faster speed
Determines the optimal token combination for a greedy tokenizer (non-greedy support coming)
Successfully identifies common phrases and figures of speech
Works with all languages and formats, even binary
Quickly skims over HTML tags, sequential spaces, tabs, etc. without wasting context
Does not require normalization
/r/MachineLearning
https://redd.it/13gdfw0
GitHub
GitHub - alasdairforsythe/tokenmonster: Ungreedy subword tokenizer and vocabulary trainer for Python, Go & Javascript
Ungreedy subword tokenizer and vocabulary trainer for Python, Go & Javascript - alasdairforsythe/tokenmonster
Best SAAS stack and template for building quick MVPs?
I want to learn a new stack. All I need is a template with authentication (firebase ideally), payment processor (like stripe), and database. Any God-tier tutorial, repo, or stack you know of? I really like Flask but I am wondering if other web frameworks allow you to do things quicker and plug things in quicker. I am hearing a lot about Next.js but yeah… not sure what to go for. All I want is a template that I can use multiple times to spam MVP after MVP. A one page presenting the product, login / logout system, some tokens given to the user and an API call to midjourney or ChatGPT that provides the thing the customer is paying for.
/r/flask
https://redd.it/13gm2ak
I want to learn a new stack. All I need is a template with authentication (firebase ideally), payment processor (like stripe), and database. Any God-tier tutorial, repo, or stack you know of? I really like Flask but I am wondering if other web frameworks allow you to do things quicker and plug things in quicker. I am hearing a lot about Next.js but yeah… not sure what to go for. All I want is a template that I can use multiple times to spam MVP after MVP. A one page presenting the product, login / logout system, some tokens given to the user and an API call to midjourney or ChatGPT that provides the thing the customer is paying for.
/r/flask
https://redd.it/13gm2ak
Reddit
r/flask on Reddit: Best SAAS stack and template for building quick MVPs?
Posted by u/Ok-War-9040 - No votes and no comments
Google Sign in AllAuth
Hey yall So i configured google and django allauth and I have successfully gotten to the sign in page for google but once I click on a gmail account I want to log in as I get a
This site can’t be reached localhost refused to connect.
Idk if its because the site was connected to the social account in the admin panel or what? I would connect the site and google but it doesn't pop up only groups, users, social accounts. any ideas?
/r/django
https://redd.it/13go7a4
Hey yall So i configured google and django allauth and I have successfully gotten to the sign in page for google but once I click on a gmail account I want to log in as I get a
This site can’t be reached localhost refused to connect.
Idk if its because the site was connected to the social account in the admin panel or what? I would connect the site and google but it doesn't pop up only groups, users, social accounts. any ideas?
/r/django
https://redd.it/13go7a4
Reddit
r/django on Reddit: Google Sign in AllAuth
Posted by u/32BitWizard - No votes and no comments
[R] Large Language Models trained on code reason better, even on benchmarks that have nothing to do with code
https://arxiv.org/abs/2210.07128
/r/MachineLearning
https://redd.it/13gk5da
https://arxiv.org/abs/2210.07128
/r/MachineLearning
https://redd.it/13gk5da
Reddit
r/MachineLearning on Reddit: [R] Large Language Models trained on code reason better, even on benchmarks that have nothing to do…
Posted by u/MysteryInc152 - 65 votes and 7 comments
Architecting Django allauth with Multi-Tenant Schemas
Hello everyone,
I am currently working on a Django project that implements a multi-tenancy architecture using the Django Tenants library. The purpose is to provide data isolation between different tenants in the system, each having its own set of schemas.
However, I am facing a critical architectural decision concerning the integration of Django allauth within this multi-tenant system. The issue arises from the fact that Django allauth inherently depends on the User model.
The challenge here is how to implement Django allauth in such a system. If I make Django allauth tenant-specific, each tenant would have its own registration and login pages, and users would need to register separately for each tenant they want to access. This also means that the same email could be used to create different accounts on different tenants, and there would be no option to share authentication or user information between tenants.
On the other hand, if I make Django allauth shared (not tenant-specific), then it becomes a challenge to manage user-tenant relationships and ensure data isolation since the User model would need to be accessible across all schemas.
I am seeking advice on the best way to implement Django allauth in a multi-tenant Django application. Has anyone faced a
/r/django
https://redd.it/13gp2g6
Hello everyone,
I am currently working on a Django project that implements a multi-tenancy architecture using the Django Tenants library. The purpose is to provide data isolation between different tenants in the system, each having its own set of schemas.
However, I am facing a critical architectural decision concerning the integration of Django allauth within this multi-tenant system. The issue arises from the fact that Django allauth inherently depends on the User model.
The challenge here is how to implement Django allauth in such a system. If I make Django allauth tenant-specific, each tenant would have its own registration and login pages, and users would need to register separately for each tenant they want to access. This also means that the same email could be used to create different accounts on different tenants, and there would be no option to share authentication or user information between tenants.
On the other hand, if I make Django allauth shared (not tenant-specific), then it becomes a challenge to manage user-tenant relationships and ensure data isolation since the User model would need to be accessible across all schemas.
I am seeking advice on the best way to implement Django allauth in a multi-tenant Django application. Has anyone faced a
/r/django
https://redd.it/13gp2g6
Reddit
r/django on Reddit: Architecting Django allauth with Multi-Tenant Schemas
Posted by u/Jugurtha-Green - 2 votes and 1 comment