Django generate thumbnail with MoviePy, problem with Path
How to get the absolute path to a video, that works in development (Windows) and production (Ubuntu), ive tried almost everything, here is the closest I've gotten to a solution, I am trying to generate a thumbnail for a video when its posted.
from pathlib import Path
BASEDIR = Path(file).resolve().parent.parent
def generatethumbnail(instance):
filename = Path.joinpath(BASEDIR, 'media/videofiles')
print(filename)
thumbnail = VideoFileClip(str(filename)+instance.video.url)
name = instance.video.url + '.png'
time = random.randrange(60)
thumbnail.saveframe('media/uploads/thumbnail' + name, t=time,withmask=True)
instance.thumbnail = name
It never gives me a good path, its ether with '/' or with \\ .
MoviePy error: the file C:\Users\User 1\Desktop\django\lumen\media\videofiles/media/uploads/videofiles/22/29/Elvis-IfICanDreamOfficialLivePerformancefcw0WKp.mp4 could not be found! Please check that you entered the correct path.
/r/django
https://redd.it/zzk4ow
How to get the absolute path to a video, that works in development (Windows) and production (Ubuntu), ive tried almost everything, here is the closest I've gotten to a solution, I am trying to generate a thumbnail for a video when its posted.
from pathlib import Path
BASEDIR = Path(file).resolve().parent.parent
def generatethumbnail(instance):
filename = Path.joinpath(BASEDIR, 'media/videofiles')
print(filename)
thumbnail = VideoFileClip(str(filename)+instance.video.url)
name = instance.video.url + '.png'
time = random.randrange(60)
thumbnail.saveframe('media/uploads/thumbnail' + name, t=time,withmask=True)
instance.thumbnail = name
It never gives me a good path, its ether with '/' or with \\ .
MoviePy error: the file C:\Users\User 1\Desktop\django\lumen\media\videofiles/media/uploads/videofiles/22/29/Elvis-IfICanDreamOfficialLivePerformancefcw0WKp.mp4 could not be found! Please check that you entered the correct path.
/r/django
https://redd.it/zzk4ow
reddit
Django generate thumbnail with MoviePy, problem with Path
How to get the absolute path to a video, that works in development (Windows) and production (Ubuntu), ive tried almost everything, here is the...
Search Vector Array of Chars
Hey guys I'm trying to create a search vector column for several fields including 2 Arrays of chars:
tags_list = ArrayField(
models.CharField(
max_length=255,
null=True,
blank=True,
),
default=list,
null=True,
blank=True,
)
related_tags_list = ArrayField(
models.CharField(
max_length=255,
null=True,
/r/django
https://redd.it/zz9jc3
Hey guys I'm trying to create a search vector column for several fields including 2 Arrays of chars:
tags_list = ArrayField(
models.CharField(
max_length=255,
null=True,
blank=True,
),
default=list,
null=True,
blank=True,
)
related_tags_list = ArrayField(
models.CharField(
max_length=255,
null=True,
/r/django
https://redd.it/zz9jc3
reddit
Search Vector Array of Chars
Hey guys I'm trying to create a search vector column for several fields including 2 Arrays of chars: tags_list = ArrayField( ...
Django admin actions for list entries
Django admin comes with custom actions for entries in a list. It works for both one value or multiple but is there any way we can add actions exclusively to an entry in the list ?
Something like the Record actions in the picture below?
https://preview.redd.it/miqivlj8o09a1.png?width=1177&format=png&auto=webp&s=71d1fb7d09f9be9af59af7bccf889961e35c9023
/r/django
https://redd.it/zyxuh4
Django admin comes with custom actions for entries in a list. It works for both one value or multiple but is there any way we can add actions exclusively to an entry in the list ?
Something like the Record actions in the picture below?
https://preview.redd.it/miqivlj8o09a1.png?width=1177&format=png&auto=webp&s=71d1fb7d09f9be9af59af7bccf889961e35c9023
/r/django
https://redd.it/zyxuh4
$1,064 Worth of 21 Programming Books by Packt for $15 ( -98% OFF)
https://dealshumb.com/pyths
/r/Python
https://redd.it/zznc19
https://dealshumb.com/pyths
/r/Python
https://redd.it/zznc19
Humble Bundle
Humble Tech Book Bundle: C# and .NET by Packt
We’ve teamed up with Packt for our newest bundle. Get books and video courses on C# programming, .NET development, and more skills for modern software developers.
Normal flask-redis works, but flask-caching w/redis ignores password
When I run this app, it works:
import redis
r = redis.Redis(password='no peeking')
r.mset({'test': 'TEST'})
x = r.get('test')
print(x)
But this one fails:
from flask import Flask
from flaskcaching import Cache
app = Flask(name)
cache = Cache(app, config={'CACHETYPE': 'redis', 'CACHEREDISPASSWORD': 'no peeking'})
cache.add('test', 'TEST')
x = cache.get('test')
print(x)
with the error "redis.exceptions.AuthenticationError: Authentication required."
Any ideas?
/r/flask
https://redd.it/zzheaa
When I run this app, it works:
import redis
r = redis.Redis(password='no peeking')
r.mset({'test': 'TEST'})
x = r.get('test')
print(x)
But this one fails:
from flask import Flask
from flaskcaching import Cache
app = Flask(name)
cache = Cache(app, config={'CACHETYPE': 'redis', 'CACHEREDISPASSWORD': 'no peeking'})
cache.add('test', 'TEST')
x = cache.get('test')
print(x)
with the error "redis.exceptions.AuthenticationError: Authentication required."
Any ideas?
/r/flask
https://redd.it/zzheaa
reddit
Normal flask-redis works, but flask-caching w/redis ignores password
When I run this app, it works: import redis r = redis.Redis(password='no peeking') r.mset({'test': 'TEST'}) x =...
4 Functions That Make Reading Python Code Easier
https://medium.com/p/eb68dceef3b8
/r/flask
https://redd.it/zzebq2
https://medium.com/p/eb68dceef3b8
/r/flask
https://redd.it/zzebq2
Medium
4 Functions That Make Reading Python Code Easier
Display the names and values clearly
Debugging a Django/Python project with VSCode and Docker
https://batiste.medium.com/debugging-a-python-project-with-vscode-and-docker-9c33670cac0
/r/django
https://redd.it/zzrly3
https://batiste.medium.com/debugging-a-python-project-with-vscode-and-docker-9c33670cac0
/r/django
https://redd.it/zzrly3
Medium
Debugging a Python project with VSCode and Docker
This guide explains how to setup a Django project and Docker together for debugging sessions within VSCode. We will follow the steps…
Does anyone know how I can fix this? I haven't used docker in the last few months (3-4) and yesterday I updated my docker and now this is happening. Now I don't know if is this because of an update or something else.
https://redd.it/zzx5dr
@pythondaily
https://redd.it/zzx5dr
@pythondaily
reddit
Does anyone know how I can fix this? I haven't used docker in the...
Posted in r/django by u/Prashant_4200 • 1 point and 0 comments
I want to know how I can create a invoice of data obtained from database (admin panel) and print it using custom django functions
/r/django
https://redd.it/zzx9xl
/r/django
https://redd.it/zzx9xl
reddit
I want to know how I can create a invoice of data obtained from...
Posted in r/django by u/-Naraku • 1 point and 1 comment
Django redirect doesn't work when trailing slash is there.
So I have a url pattern which looks like this
urlpatterns = [
path('register-user/', views.registerUser, name='registerUser'),
path('register-vendor/', views.registerVendor, name='registerVendor'),
path('login/', views.login, name='login'),
path('logout/', views.logout, name='logout'),
path('dashboard/', views.dashboard, name='dashboard'),
path('vendor-dashboard/', views.vendorDashboard, name='vendorDashboard'),
path('my-account/', views.myAccount, name='myAccount'),
]
and views
def myAccount(request):
user = request.user
redirectUrl = detectUser(user)
return redirect(redirectUrl)
def dashboard(request):
return render(request, 'accounts/dashboard.html')
def vendorDashboard(request):
return render(request, 'accounts/vendor-dashboard.html')
the detect user function detects and user type and returns respective URL
def detectUser(user):
if user.role == 1:
redirectUrl = 'vendor-dashboard/'
elif user.role == 2: redirectUrl = 'dashboard/'
elif user.role == None and user.is_superadmin:
redirectUrl = 'admin'
return redirectUrl
but when I see the website the URL is
/r/django
https://redd.it/zzspi2
So I have a url pattern which looks like this
urlpatterns = [
path('register-user/', views.registerUser, name='registerUser'),
path('register-vendor/', views.registerVendor, name='registerVendor'),
path('login/', views.login, name='login'),
path('logout/', views.logout, name='logout'),
path('dashboard/', views.dashboard, name='dashboard'),
path('vendor-dashboard/', views.vendorDashboard, name='vendorDashboard'),
path('my-account/', views.myAccount, name='myAccount'),
]
and views
def myAccount(request):
user = request.user
redirectUrl = detectUser(user)
return redirect(redirectUrl)
def dashboard(request):
return render(request, 'accounts/dashboard.html')
def vendorDashboard(request):
return render(request, 'accounts/vendor-dashboard.html')
the detect user function detects and user type and returns respective URL
def detectUser(user):
if user.role == 1:
redirectUrl = 'vendor-dashboard/'
elif user.role == 2: redirectUrl = 'dashboard/'
elif user.role == None and user.is_superadmin:
redirectUrl = 'admin'
return redirectUrl
but when I see the website the URL is
/r/django
https://redd.it/zzspi2
reddit
Django redirect doesn't work when trailing slash is there.
So I have a url pattern which looks like this urlpatterns = [ path('register-user/', views.registerUser, name='registerUser'), ...
Help with identifying Users uniquely without Log in
Hello I have built a simple quote website for fun using Django Rest Framework and React js and I want to add a LIKE function to it but I want it to be without Logging in.
How can i achieve this with Django? How can i uniquely identify the Anonymous User without asking for Login In.
/r/django
https://redd.it/zzt3gu
Hello I have built a simple quote website for fun using Django Rest Framework and React js and I want to add a LIKE function to it but I want it to be without Logging in.
How can i achieve this with Django? How can i uniquely identify the Anonymous User without asking for Login In.
/r/django
https://redd.it/zzt3gu
reddit
Help with identifying Users uniquely without Log in
Hello I have built a simple quote website for fun using **Django Rest Framework** and **React js** and I want to add a LIKE function to it but I...
export to excel(.xls)
i am using python xlwt module to convert my database query into an excel sheet.everything works fine,but now i want to adjust my date coloumn as below
def tonerdetails_export_toexcel(request,id):
toner_model = find_toner_model(id)
fmt = '%Y-%m-%d %H:%M:%S'
response =HttpResponse(content_type='application/ms-excel')
response['Content-Disposition']='attachment; filename=TonerReport ' + str(toner_model) + '.xls'
wb=xlwt.Workbook(encoding='utf=8')
ws=wb.add_sheet('Toner Report')
row_num=0
font_style=xlwt.XFStyle()
font_style.font.bold=True
date_format = xlwt.XFStyle()
date_format.num_format_str = 'yyyy/mm/dd'
columns=['Toner Model','Issued To','Employee Name','Employee Designation','Date Dispatched','Status']
for col_num in range (len(columns)):
ws.write(row_num,col_num,columns[col_num],font_style)
font_style = xlwt.XFStyle()
rows=TonerDetails.objects.filter(toner_model_id=id).values_list('toner_model_id__toner_model','issued_to_id__name','employee_name',
/r/django
https://redd.it/zzp8f4
i am using python xlwt module to convert my database query into an excel sheet.everything works fine,but now i want to adjust my date coloumn as below
def tonerdetails_export_toexcel(request,id):
toner_model = find_toner_model(id)
fmt = '%Y-%m-%d %H:%M:%S'
response =HttpResponse(content_type='application/ms-excel')
response['Content-Disposition']='attachment; filename=TonerReport ' + str(toner_model) + '.xls'
wb=xlwt.Workbook(encoding='utf=8')
ws=wb.add_sheet('Toner Report')
row_num=0
font_style=xlwt.XFStyle()
font_style.font.bold=True
date_format = xlwt.XFStyle()
date_format.num_format_str = 'yyyy/mm/dd'
columns=['Toner Model','Issued To','Employee Name','Employee Designation','Date Dispatched','Status']
for col_num in range (len(columns)):
ws.write(row_num,col_num,columns[col_num],font_style)
font_style = xlwt.XFStyle()
rows=TonerDetails.objects.filter(toner_model_id=id).values_list('toner_model_id__toner_model','issued_to_id__name','employee_name',
/r/django
https://redd.it/zzp8f4
reddit
export to excel(.xls)
Posted in r/django by u/muneermohd96190 • 0 points and 4 comments
Flask run fail after Python update
I updated my Python from version 3.9.2 to 3.11.1 on a Windows 10 machine. I reinstalled Flask and other modules I needed for the new Python version through pip and it seems that my apps work as normal when I use
One think I have noticed, but I have no idea if this relevant or not, is that the old Python was installed under C:\\Program Files while the new one is only installed in AppData/Local even though I installed it for all Users. Plus I can't change the installation path in the setup program, even when running it as Administrator.
/r/flask
https://redd.it/1002wun
I updated my Python from version 3.9.2 to 3.11.1 on a Windows 10 machine. I reinstalled Flask and other modules I needed for the new Python version through pip and it seems that my apps work as normal when I use
python -m flask run. However just flask run still looks for the old (and now uninstalled) Python 3.9 and of course fails as the system can't find the files. How can I fix this? I tried uninstalling it and reinstalling it with no success. One think I have noticed, but I have no idea if this relevant or not, is that the old Python was installed under C:\\Program Files while the new one is only installed in AppData/Local even though I installed it for all Users. Plus I can't change the installation path in the setup program, even when running it as Administrator.
/r/flask
https://redd.it/1002wun
reddit
Flask run fail after Python update
I updated my Python from version 3.9.2 to 3.11.1 on a Windows 10 machine. I reinstalled Flask and other modules I needed for the new Python...
Operational error after changing the operating system
Dear Flask developers,
\-I built my flask app on WSL(Windows Subsystem for Linux) without a problem and it is working on WSL.
\-In order to test my app on a server environment I copied my app to an OpenBSD virtual machine on Hyper-V.
\-Ran my app on the local network.
\-I tried to connect from a different machine to the server(OpenBSD VM). Connected without a problem.
\-There is a login screen in my app and when I try to login as a user I got an operational error:
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: Users
SQL: SELECT "Users".id AS "Users_id", "Users".email AS "Users_email", "Users".password AS "Users_password", "Users".option_1 AS "Users_option_1", "Users".option_2 AS "Users_option_2", "Users".option_3 AS "Users_option_3"
FROM "Users"
WHERE "Users".email = ?
LIMIT ? OFFSET ?
parameters: ('test_1@test.com', 1, 0)
(Background on this error at: https://sqlalche.me/e/14/e3q8)
​
Traceback (most recent call last)
File "/home/user/.local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1900, in executecontext
self.dialect.doexecute(
File "/home/user/.local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 736, in doexecute
cursor.execute(statement, parameters)
Could
/r/flask
https://redd.it/zzuv8x
Dear Flask developers,
\-I built my flask app on WSL(Windows Subsystem for Linux) without a problem and it is working on WSL.
\-In order to test my app on a server environment I copied my app to an OpenBSD virtual machine on Hyper-V.
\-Ran my app on the local network.
\-I tried to connect from a different machine to the server(OpenBSD VM). Connected without a problem.
\-There is a login screen in my app and when I try to login as a user I got an operational error:
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: Users
SQL: SELECT "Users".id AS "Users_id", "Users".email AS "Users_email", "Users".password AS "Users_password", "Users".option_1 AS "Users_option_1", "Users".option_2 AS "Users_option_2", "Users".option_3 AS "Users_option_3"
FROM "Users"
WHERE "Users".email = ?
LIMIT ? OFFSET ?
parameters: ('test_1@test.com', 1, 0)
(Background on this error at: https://sqlalche.me/e/14/e3q8)
​
Traceback (most recent call last)
File "/home/user/.local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1900, in executecontext
self.dialect.doexecute(
File "/home/user/.local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 736, in doexecute
cursor.execute(statement, parameters)
Could
/r/flask
https://redd.it/zzuv8x
reddit
Operational error after changing the operating system
Dear Flask developers, \-I built my flask app on WSL(Windows Subsystem for Linux) without a problem and it is working on WSL. \-In order to test...
Deploying an application to “production” in AWA
I have a Django app. I totally messed up it’s configuration and I can’t get it running. Honestly, I have no idea how I got in running in the first place a year ago. I’m not comfortable at all with Apache etc.
I’d like to reset it up from scratch. Are there any great, detailed tutorials. I need to use my custom domain and SSL as well.
Please help :)
/r/django
https://redd.it/1006r4u
I have a Django app. I totally messed up it’s configuration and I can’t get it running. Honestly, I have no idea how I got in running in the first place a year ago. I’m not comfortable at all with Apache etc.
I’d like to reset it up from scratch. Are there any great, detailed tutorials. I need to use my custom domain and SSL as well.
Please help :)
/r/django
https://redd.it/1006r4u
reddit
Deploying an application to “production” in AWA
I have a Django app. I totally messed up it’s configuration and I can’t get it running. Honestly, I have no idea how I got in running in the first...
Sunday Daily Thread: What's everyone working on this week?
Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.
/r/Python
https://redd.it/10073zi
Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.
/r/Python
https://redd.it/10073zi
Reddit
r/Python on Reddit: Sunday Daily Thread: What's everyone working on this week?
Posted by u/Im__Joseph - 5 votes and 22 comments
Is it possible to set the USERNAME_FIELD to email without having to build a custom manager and forms from scratch?
Im trying to setup a user model with an added birthday field and remove the username field. Can I do this using the usercreation forms and built in manager? Or would I still have to create my own from scratch
/r/djangolearning
https://redd.it/100ai5k
Im trying to setup a user model with an added birthday field and remove the username field. Can I do this using the usercreation forms and built in manager? Or would I still have to create my own from scratch
/r/djangolearning
https://redd.it/100ai5k
reddit
Is it possible to set the USERNAME_FIELD to email without having...
Im trying to setup a user model with an added birthday field and remove the username field. Can I do this using the usercreation forms and built...