#web-development
2 messages · Page 175 of 1
It could be that something in the installation of uWSGI went wrong, or that it's a configuration error
TLDR; Flask or NodeJS for a web app (100k users) 0.5-2k active at a time.
I am hosting a web app for around 100k+ users.
Currently i have made a flask app served via gunicorn to be hosted on Heroku or another VPS.
It is not a big web app, its a simple service to allow users to connect their LINE account with my service and every 1hourly i send web requests to LINE API endpoints from the collected users information.
Q. Should I switch from Flask to NodeJS ?
I haven't deployed the service yet, but yes, tests works fine for now.
Q. Would NodeJS provide me with better performance in terms of sending web requests to an API endpoint (around 15-20k requests) every hour My service is a notification service which sends hourly notifications via LINE app
I need to be able to save user tokens when they login with my service, to some sort of database. Im using Sqlite for development and MySQL for production right now
*Database entries yet to be grabbed. So no database migration required. I can work on different database is need be.
shortly speaking, if you want to speed up your application, use caching and load balancing
and it would not matter which framework you used
it only depends on where you remember/easier to find the syntax to implement caching between app and db
and at the same can be applied caching at level of reverse proxy, which is sometimes called web accelerator I think
basically, I think there is no difference between Flask and NodeJS in terms of performance, it totally depends on your skills to use it
i want to create a page (only admin access) where displays users list with all the data, how can i do it ?
Thanks darkwind, i get the point. I think i should then just stick to Python for this. I have more experience with Flask than NodeJS.
Thank you
Hi. I have an application that I developed with the flask framework. I intend to send a number of real-time notifications from the server to the client. I want to know if I use a web socket or a socketio! The problem with socketio is that it cannot launch multiple workers.
hey guys
How do i flip boolean value in django admin list action?
i tried this but it doesnt work:
@admin.action(description='Toggle featured product')
def toggle_featured(modeladmin, request, queryset):
t = queryset.filter(featured=True)
f = queryset.filter(featured=False)
t.update(featured=False)
f.update(featured=True)
make folder name "templates" note case sensitive dont make mistakes
any django (kind of exp dev)?
i need some strong suggestion's
Just ask your question
so sir i dont have any particular question but im kind stuck so i'm constantly working on django from last 2 months , i have made many apps like a simple bs4 proj then todo app then blog then user auth apps and was making a e-commerce app by own from last some days , learned many things but sometimes i get stuck how can i take my django skills to next lvl and i have saw Corey Schafer's Playlist , Clever Programmer 8 hrs vid and begginers those 10 parts docs .. Then while making project also learned many things like Search Functionality backend , now how can i get to more advanced + i have 1 kind of problem
Start learning something like django-rest-framework
ohh but i have to master this django
And make a api
ohh
ik what is api
but idk ppl say api
;-;
plz explain
i know api but then too idk
haha
half knowledge
application programming interface (api) is a connection between computers or between computer programs. It is a type of software interface, offering a service to other pieces of software.
and i have like 3-4 problems which i can only explain in voice chat or show in screen share
i have no teacher
self learner from india age 16
;-;
example
You see buttons like sign up with google in websites right?
yes
It uses googles api and signs you up automatically according to your google account info
Yes
#751592231726481530 I guess you can ask here
is anyone experienced in flask?
i have an assignment and don't know how to solve it.
You can request video permissions from a mod who's in one of the voice chats
@calm plume
Ohk
And what's ur opinion
I have no idea what your question is
@calm plume read this out
Question
It's about how can i move forward now
What should i do how when From where And why ..
And it contains what i have done
And Ofc Django query
Have you messed with DRF?
Nah never gone through
Django Rest Framework
And planned to do it after mastering django
Like how can give users option to sign up with Google
Is it feature of drf
And payment Stripe Gateaway also idk
Like Youtubers put thier yt vid on thier site
By yt api that too idk
And Google Maps api
Idk that too
Umm
Are those all done by drf or also can be done by Django
If you're looking to "master" anything, that's pretty hard. I say just learn the basics, and then keep adding diffrent parts when you need them
Youtube videos on a website is an iframe service provided by youtube, not a django thing
And Google maps
And Payment Gateaway
I have gone too far from basics now lol
payment gateway you could do through the stripe api https://stripe.com/docs/api?lang=python
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
That's not django specific
Ohh
Means i have Learned django
But but then too some too (i say insane lvl ) problem's which i can only explain while screen share
Like my Order History fun have. A prob
@calm plume
In django is it bad practice to declare divs and other html elements on views?
it sure looks bad
What would that accomplish?
I am putting a list of week dates on webpage
And if it's today I put text into the div which says today
and also color it blue
I think you should be handling that in your templates.
Based on what data your function returns.
hmm... It's a bit difficult, because I am wrapping the day name into <strong> tag. Maybe I just render them at different times, but then the alignment might not be always correct.
So aren't you just returning the date? Could you just return a value/object/context that also sets the day of the week, and then in your template display {{object.day}} or whatever?
I'll experiment with different ways of doing in. Right now I return a list to the template and mark it as safe and that works fine for now.
how to i not let something get deleted.
i'm doing a contenteditable="true" thingy on a <pre> tag and there's something inside it that'll be gone the moment i press Ctrl + A and backspace how do i prevent user from doing that?
the html code:
<pre id="code" contenteditable="true" oninput="update()"><code id="code2" class="language-python"></code></pre>
so uh the code2 object will die as soon as i do ctrl+a backspace
how do i prevent that
*ping to notify 😄
Django admin, project hosted on PythonAnywhere. Why does the add page look like this?
especially the top part, everything else is fine I think
???
Are you using some kind of 3rd party admin template?
No
yeah, refreshing does nothing....
Is it different locally?
rest of the pages.... let me test
Ok so it's fine on your machine, but not when you deploy it.
yeah
I know Django 3 changed the admin templates a bit in terms of layout.
....this is a different model.... same result
Well if it works fine locally, and you're sure it's the same code, then that rules out the code being an issue. Maye the CSS isn't loading properly.
Or some dependency isn't installed?
I'm just tryin to think what else could be different on a different machine.
hmm
I'm going to have to do a pip freeze
also, this is what it looks like locally... the dark mode... not sure where it is coming from
welp, the list on PythonAnywhere is really long, lol
though I ran the same commands while doing it on the site... no extra things where added
nope, wrong version of django apparently :/
could've swarn I got the right one (3.2)
how to update a flask page when its like refreshed like imagine i have variable
a = 'a'
@app.route('/'):
...
return render_template('../home/home.html', var=a)
now for example i changed the variable to a='b' i want it to update when i refresh now, as of now when i refresh the page it still shows a
You can use some
to reload the page
can you give a little example how to do that
location.reload();
Haven't tried it should work
And how will the values be changing while a user is viewing the page?
so like i would create a .js file then name it something then type this then?
i dont want while the viewer is viewing the page i want it when the user reloads/refreshes the page
so you want the content to change when they refresh the page?
yes
how will you be getting the value a?
will it be a constant or will it be a value returned by another function?...
home.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>None</title>
</head>
<body>
{{ var }}
</body>
</html>
you can use some 
?
okay
how will you be defining the value a?
it would be called from a text file
The text file contents wont change
they will change
Oh
is their way like when we refresh the page in a browser, it sends this in terminal 127.0.0.1 - - [26/Jul/2021 21:54:45] "GET / HTTP/1.1" 200 -
so is there a way to like reload the value of a from the text file when this is sent in terminal or when the webpage is updated?
then you can open the text file and read it and set the value to a, a will be what ever the text files content will be
so if i change the text file contents the value of a will chnage?
yes, it should
but if you are changing the value of a manually while the server is running it won't update in the front end
it didnt work
Show your code
didn't realize there was an ongoing discussion will come back later
its ok, send your question here
app = Flask(__name__, template_folder="webpage")
app =
with open('value.txt') as f:
a = f.read()
@app.route('/')
def test():
return render_template("index.html", var=a)
if __name__ == '__main__':
app.run(host="localhost", port=3001)
How to learn django if I'm stupid
put a inside the function, then it will read the file every time when a request is made
like this?
def return_a():
with open('value.txt') as f:
return f.read()
@app.route('/')
def test():
return render_template("index.html", var=return_a())
i want to create a page (only admin access) where displays users list with all the data, how can i do it ?
👍
Basically like this:
from django.contrib.auth import get_user_model
User = get_user_model()
users = User.objects.all()
and then add the loginMixIns
and make it return what you want
how to learn django if im very stupid
Official django tutorial https://docs.djangoproject.com/en/3.2/intro/tutorial01/ or youtube tutorial
yeah im not that stupid
Official tutorial is good for everyone
or just go for the docs and start building / testing things out
i just noticed i put the polls folder in a wrong directory
what's the error
You press submit and it sits there?
What's the form code in your html?
how can we create reset password functionality without ```py
from django.contrib.auth import views
in django
why is there a space after eventform everywhere?
ok
I can't quite remember exactly, but either you can use action="" in the form to signifiy which function to use
but you shouldn't have to I think
but sometimes that helps to be specific
look up using a form in django templates and usign action="" in the form
the "" being the function to use
err, whatever, flask.
But you should at least be getting an error if that's the case.
If nothing happens, then the form isn't submitting through the backend.
Does flask have a debug mode? Like if a function has an error, does it display it on your page?
Yea so then there's probably no obvious functional error. It just isn't doing anything
First box shows them using action.
You did what in terminal?
Maybe take the date out and see if it works.
So you at least know your form works or not.
Uh no, just remove it from your form and make your function not require it (and of course make it not required in the DB if you must)
I would still expect the webpage to give you an error page/500 or something if the backend was the problem.
Before you do all that, just add the action to the form
like it shows at that link
the route in the quotes for action="" should be from your urls/routes file
that then points at the function that handles the form on the backend
ok and it's pointing at one of your urls?
and that url points to which function?
can you paste your urls file and the function it goes to?
So I don't know how flask works exactly, but this doesn't look right.
project_id=1
eventform = CreateEvent()
isn't that supposed to be a function?
isn't the @ just a decorator on a function?
👀
Without the date?
Sweet deal.
So at least now you know that and can figure out why that error is happening.
first result on google
flask or django
umm does it have all those syntax highlight ??
so you have to find a way to match the date syntax, if they are different
what's the datefield on the form passing to the backend, a string?
usually you need to convert that to a datetime object on the backend.
print it from your function
print the value being passed into the function
Depends how you pass it. Maybe a value name, maybe kwargs/args, I don't know. You left that out above.
you might be able to print the post request
from django.urls import path
from . import views
from django.contrib.auth import views as v_views
app_name='users'
urlpatterns = [
path('register/',views.register,name='register'),
path('login/',v_views.LoginView.as_view(template_name='users/login.html'),name='login'),
path('order_history/',views.order_history,name='order_history'),
path('logout/',v_views.LogoutView.as_view(template_name='users/logout.html'),name='logout'),
path('password_reset',v_views.PasswordResetView.as_view(),name='password_reset'),
path('password_reset_done',v_views.PasswordResetDoneView.as_view(),name='password_reset_done'),
path('password_reset/<uidb64>/<token>/',v_views.PasswordResetConfirmView.as_view(),name='password_reset_confirm'),
path('password_reset_complete',v_views.PasswordResetCompleteView.as_view(),name='password_reset_complete')
]```
Where is the password_reset function? @dusk portal
it's in built in django ;-;
what u mean
lol
<tr>
<!-- this is a random profile image not customizable, for now -->
<td class="py-1">
<img src="../../assets/images/faces-clipart/pic-1.png" alt="image" />
</td>
<td> HERE THE NAME AND LASTNAME </td>
<td> HERE EMAIL </td>
<td> HERE USERNAME</td>
<td> HERE DATE OF REGISTRATION </td>
</tr>
<tr>
how can i create a loop that gives that informations for each user
like to create a table
@elder nebula
Got a FastAPI webapp which I'm presently running with uvicorn.
I'm configuring logging to use structlog as I liked it's easy approach to getting JSON log output.
Now, I am battling uvicorn which seems to start some loggers - but its website doesn't cover how to override logging to any great detail. It only seems to concern itself with taking a dict based logging config, instead of e.g. some factory hook method one could override.
Anyone been in this situation ? I want uvicorn's log output, I do NOT want it formatted the way it is, I want to use a structlog logger.
Do you use flask or django?
django
You can use a for loop in the template. @native tide
yes i know but i dont know how to do it (im a beginner programmer)
^^
^^
If we want to send an email through python, do we need to enter our password, or can we do it with authentication/authorization key?
Alright so first return it in the context
like so in your views.py
from django.contrib.auth import get_user_model
def my_view(request):
User = get_user_model()
context = {
'users': User.objects.all(),
}
return render(request, 'index.html', context)```
Now inside `index.html`
```html
{% for user in users %}
{{ user }}
{% endfor %}```
in your urls.py
```py
from .views import my_view
urlpatterns = [
path('users/' my_view, name="users")
]```
And you should be ready to go
I've got two microservices that need to have the same django model. Is there any way to automatically update both models if I change one?
i should learn django 2 or django 3?
3
thanks bro after hours i did it
like how can i add a number for each user
@native tide take a look at forloop.counter
https://docs.djangoproject.com/en/3.2/ref/templates/builtins/#for
thanks bro
i was looking to integrate my dash app into my flask and i saw a solution in where you can just link it and it appears like two websites how would i do that?
]
this si what it said
you mean you wish to update the code of your django project automaticlaly in second project, if it is changed in the first one?
tbh, it sounds like you just should split your database properly between them
otherwise... i don't know, in any of them writing extra careful SQL request that is not tied to changable model as maximum as it is posible?
if necessary writing in raw SQL language
there are some other choices, but there are much worse
my most recommended choice: Split database proplerly, so it would be independent between them
as half silly easiest choice, make second application, requesting data from first one to make copy of db
or tie data with some specified key between those two dbs
Anyone tried starlette, responder & fastapi instead of flask for full stack, and did you come across any issues
Hi, does anyone has a good way to automaticallyc reate a profile in Django without going through the hassle of using python manage.py createsuperuser ?
I'm thinking why u wanted to do this without this command?
It's so much simple bro
Even a 8 years kid can easily do
Oh I don't know. Maaaaaybe I wanted to make the process like, automatic?
U do not have to run this command every time
Only 1 time
For creating Owner of That Admin page
Who will be like
Who will have ownership there
;_;
If u don't use that impossible cez if u make users directly how will they get permission to login toh admin panel
😂😂
No logic bro
ok then, what about a list of users for testing
But why u wanted to do that
I saw ppl some ppl using Own admin page
Saw 1st person to work extra
Why u wanted to work extra
;_;
Same output
Ohh
And I have a habit to purge data when I no longer need it

ofc in prod I will only need the CLI
Hey guys! I am going start to learn Django very soon. Can anyone recommend me the best, easy to understand course/video lectures online available.
Thanks in advance
I have an XML file which in some elements I deepcopy the element and make 2 types of it. But they also have a unique field id. I try to seperate same elements by adding 'R' to the id. Well thats what im hoping for, but I cant override the value. Can someone see whats going on in here?
Deepcopy elements:
estate_for_rent = copy.deepcopy(raw_item_data)
estate_for_sale = copy.deepcopy(raw_item_data)
Changing value and printing it out:
print("sale id: ", estate_for_sale.xpath('./@id')[0])
print("rent id: ", estate_for_rent.xpath('./@id')[0])
estate_for_sale.xpath('./@id')[0] = estate_for_sale.xpath('./@id')[0] + 'R'
print("sale id after: ", estate_for_sale.xpath('./@id')[0])
print("rent id after: ", estate_for_rent.xpath('./@id')[0])
Output:
sale id: 12614
rente id: 12614
sale id after: 12614
rent id after: 12614
Output should be for example: estate_for_rent id = 12614 and estate_for_sale id = 12614. What am I doing wrong?
can someone help with dashboard for discord
if you have linkedin learning there are a good django courses, if you stick to the free stuff check Tech with Tim or Corey Schafer videos on youtube, there is one 1hour introduction by Code with Mosh so you can check this for a fast overview of django
how can I put the "name" in the registration as optional
damn, I'm gonna learn JS by the rate I use Selenium for my project
solution:
blank=True
You got it working?
the numbering system?
yes yes
great
Is anyone here familiar with typed Django? I'm running into a problem with hinting authenticated requests that I'm sure other people have run into before.
The django-stubs docs suggest that authenticated requests can be hinted with an AuthenticatedHttpRequest class that looks something like this:
from django.http import HttpRequest
from foo.models import FooUser
class AuthenticatedHttpRequest(HttpRequest):
user: FooUser
The issue is that foo.FooUser isn't always the user model throughout the project - this monolith can be deployed under different conditions, some where we can be sure that request.user will always be bar.BarUser. I'm wondering if there's some idiomatic method to hint request.user that maybe pulls from django-stubs' internal magick for pulling user classes?
Apparently doing something like user: get_user_model() is an illegal type annotation since call expressions aren't allowed, but I can't think of a nicer way to handle this
Hello guys,I want to make a web site where user can enter information like : email,lastname,firstname, age ... In order to have them in a database.Can someone give some tips what language , framework are better to do that.I wanna need help.
hi guys i have a question. If i wanted to design a website manually, is there any website that would allow me to do that but also be able to provide the html,css and javascript code for the design that i would have made?
There is this tool called webflow that allows you to visually make css and js and then export it
at least i think
You can use python as the programming language and django as the web backend
python, flask
Yes there are, but in my experience the css they generate is messy and use position absolute which can make the process much slower since you need to create the design for every screen size. Those are fine if you want to design, but for production, not so good. I would use bootstrap for those
Thanks.Assuming I am a hard-working young person , how long that can take me to do that?I already knew a lot stuff about python.
Thanks
do you have experience using django?
if you have never programmed before then it will take a few months
In django there's built-in users / authentication which takes user email, username, firstname and lastname date created. If you want to add anything to that, it's possible
Yes
It's pretty quick.
They are both easy, but flask is good for prototyping / doing lightweight stuff so django might be a overkill if you want to just store user data.
I already programmed some stuff in python related to my jod
jod?
What are you planning to do with the web app?
Definitely I must to learned Django.
When i was starting out in web development, i used flask and it was simple and easy for me to get started on a web application
Django is good choice, most companies use it.
companies also use flask
Yes they do
flask is so light and simple whilst teaches you alot about how everything works
Online registration for a course .
Then django is a good choice in my opinion
oo i see thank you for the suggestion, ill try it out.
bootstrap for the production of the website?
Thanks guys for your tips . I'm going make more research about flask and django and choose what is better for me.
You can use what you want. It was just a recommentation
ah i see.thanks.
Hello
I have been learning django for a while now but from time to time i feel like i should've started with Flask or something else that lets u build more things from scratch
Django is a lot nicer imo, since it handles database stuff for you
It's batteries-included style is what I prefer more than Flask
So if u have been doing web for sometime and encountered with some web frameworks do advise me to stop and start all over againg or just continue
For most projects, I'd use Django or FastAPI, both are really great
It's batteries-included style is what I prefer more than Flask
@calm plume yea
But there are somethings that i feel wired about
Like i understand it but not really or i feel that i got it but there's something in it that didn't click and i don't know what is it
Django is pretty confusing, yeah. The only way to really understand it is build projects in it.
Yea im doing it
I made a poll app and a small blog app
I looked alot into djangos files to understand how it works but it is too complicated and eats hell alot of time, Pushes to think i should have started with flask
Django was confusing for me until I fully understood how it's supposed to be used
Like what is supposed to go into views.py ect
Was it ur first framework?
Flask is very good to build prototypes fast, that's what I used it for. And if I want to do complicated apps I make them in Django. The django is very fast to build big projects. Flask is fast to do smaller things and setup faster
You can do both in both if you want. It's just flask has less ready and django has more ready made. Sometimes django has too much ready.
I think ill start flask
Yeah, it has most of the stuff they want built in
I tried both. I use both in different things
Anyone use Django's auth in addition to JWTs? Like for password reset?
i would agree. flask is very simple to start with. Django needs so many files bc it does butt tons more than flask
along with hundreds of other open source packages adding graphql, rest, jwt auth, forms, css, other db engines
why is this button not being centered
.quickplay {
position: absolute;
text-decoration: none;
color: white;
text-align: center;
margin: 0;
font-size: 45px;
background-color: purple;
border-radius: 10px;
padding: 0px 10px;
transition: 0.4s;
}
<span class="page-content">
<a class= "quickplay" href="/templates/quickgame.html">Test</a>
</span>
It might be centered in the span, but is the span centered?
oh that might be the issue
well I did this
.center {
text-align: center;
}
<span class="page-content center">
<a class= "quickplay" href="/templates/quickgame.html">Test</a>
</span>
didn't center it
what's the page-content css
And what is the span inside of?
Because that div probably needs centering as well
this is what I did
<div style="width: 100%;">
<span class="page-content center">
<a class= "quickplay" href="/templates/quickgame.html">Test</a>
</span>
</div>
.center {
text-align: center;
}
still not centered
you didn't center the div
oh
How to send code like this please tell me
it's just a screenshot from a website
How you organise it
it's a screen shot
Ohh
There ya go. 🙂
thats not the center tho
Maybe there's a margin/padding somewhere.
Sure thing.
yeah - I think raw SQL queries are the way to go... have both microservices connected to the same db (now, one is postgres the other is sqlite), but the issue is that both my microservices use DRF ModelSerializers which require a model, honestly I'll just manually change it it's not like the models will change at all...
how can I move a button (<a> tag) 5 pixels down when I hover over it? This is what I tried
.quickplay:hover {
transform: translateY(5px);
}
I want to get into web developpement. I'm planning in learning django. I'm fine with backend and stuff but the only problem is front end because I'm not very creative
Is there some sort of drag and drop app for html and css
You'll find many WordPress editors. Wix, webflow are also drag and drop. Figma allows you to export you prototypes as html.
But it you want to get good at this, you'll have to eventually learn them and practice
Ok thx I'll check them out
I have a website with a (react) frontend and (laravel) backend. I use axios for react so I can do CRUD Methods easily, but when I do a POST Method from an HTML form to the laravel api it shows this error (419 unknown). I saw some solutions but it was for laravel-react apps like the react library inside the laravel framework and they used blade.php to solve it, but thats not the case for me, I am hosting the laravel api and making CRUD from react just like a public api
Make sure to be passing a csrf token with the request
@mint folio
How to pass a csrf token with the request and do I pass it in (axios) or in (laravel)
In addition, in postman the POST Method works fine with a token, it also worked when I POST it for the first time with axios (if this helps)
Csrf should only apply to web routes not api. So you shouldn’t put api routes in web routes file as the web guard has csrf protection by default. https://github.com/laravel/laravel/blob/8.x/app/Http/Kernel.php#L38
Maybe this server is not best place to ask, for Laravel
anyone's up
app_name='users'
urlpatterns = [
path('register/',views.register,name='register'),
path('login/',v_views.LoginView.as_view(template_name='users/login.html'),name='login'),
path('order_history/',views.order_history,name='order_history'),
path('logout/',v_views.LogoutView.as_view(template_name='users/logout.html'),name='logout'),
path('password_reset/',v_views.PasswordResetView.as_view(),name='password_reset'),
path('password_reset_done/',v_views.PasswordResetDoneView.as_view(),name='password_reset_done'),
path('password_reset/<uidb64>/<token>/',v_views.PasswordResetConfirmView.as_view(),name='password_reset_confirm'),
path('password_reset_complete',v_views.PasswordResetCompleteView.as_view(),name='password_reset_complete')
]```
@elder nebula u pro here wow
path('password_reset/<uidb64>/<token>/',v_views.PasswordResetConfirmView.as_view(),name='password_reset_confirm'), oh you have it here
The problem is the app_name='users', which means django can't find the right reverse.
path(
'password_reset/<uidb64>/<token>/',
v_views.PasswordResetConfirmView.as_view(
success_url=reverse_lazy('users:password_reset_complete')
),
name='password_reset_confirm'
),
and import the from django.urls import reverse_lazy
you might also need to fix the other password views
oh just need to import it?
yes
it works?
no
so
from django.urls import path
from . import views
from django.contrib.auth import views as v_views
from django.urls import reverse_lazy
app_name='users'
urlpatterns = [
path('register/',views.register,name='register'),
path('login/',v_views.LoginView.as_view(template_name='users/login.html'),name='login'),
path('order_history/',views.order_history,name='order_history'),
path('logout/',v_views.LogoutView.as_view(template_name='users/logout.html'),name='logout'),
path('password_reset/',v_views.PasswordResetView.as_view(),name='password_reset'),
path('password_reset_done/',v_views.PasswordResetDoneView.as_view(),name='password_reset_done'),
path('password_reset/<uidb64>/<token>/',v_views.PasswordResetConfirmView.as_view(),name='password_reset_confirm'),
path('password_reset_complete',v_views.PasswordResetCompleteView.as_view(),name='password_reset_complete')
]``` this is my code rn
replace the ```py
path('password_reset/<uidb64>/<token>/',v_views.PasswordResetConfirmView.as_view(),name='password_reset_confirm'),
with the
```py
path('password_reset/<uidb64>/<token>/',v_views.PasswordResetConfirmView.as_view(success_url=reverse_lazy('users:password_reset_complete')),name='password_reset_confirm'),
hmm
Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name.
did you close the server and run it again?
yes
also
path('password_reset/',v_views.PasswordResetView.as_view(),name='password_reset'),
replace with
path('password_reset/',v_views.PasswordResetView.as_view(success_url=reverse_lazy('users:password_reset_done')),name='password_reset'),
yes yes
app_name='users'
urlpatterns = [
path('register/',views.register,name='register'),
path('login/',v_views.LoginView.as_view(template_name='users/login.html'),name='login'),
path('order_history/',views.order_history,name='order_history'),
path('logout/',v_views.LogoutView.as_view(template_name='users/logout.html'),name='logout'),
path('password_reset/',v_views.PasswordResetView.as_view(),name='password_reset'),
path('password_reset_done/',v_views.PasswordResetDoneView.as_view(),name='password_reset_done'),
path('password_reset/<uidb64>/<token>/',v_views.PasswordResetConfirmView.as_view(success_url=reverse_lazy('users:password_reset_complete')),name='password_reset_confirm'),
path('password_reset_complete',v_views.PasswordResetCompleteView.as_view(),name='password_reset_complete')
]```
this is my code rn
ohh
wait doing
still
lol
ohh I see it
hmm
change it to users:password_reset_confirm
hmm
you don't?
if u see my urls
u can see name
i dont have any url named with
change it to users:password_reset_confirm
``` this
what about this path('password_reset_complete',v_views.PasswordResetCompleteView.as_view(),name='password_reset_complete')
name="password_reset_complete"
and the app_name is the prefix
guys
i got a question
this is my utility class:
.flex {
display: flex;
}
.flex-y-center {
align-items: center;
}
.flex-x-center {
justify-content: center;
}
@dusk portal One solution is to override the file with your own template
is it inefficient to use display:flex before every center thing so that i dont have to use flex
yes it can be done ezily
like this:
path('password_reset/<uidb64>/<token>/',v_views.PasswordResetConfirmView.as_view(template_name="password_reset_confirm.html", success_url=reverse_lazy('users:password_reset_complete')),name='password_reset_confirm'),
Try that, it might be the only way
then why would i use this i will just add template_name
because you have the reverse prefix users
as app name
otherwise django don't know which app to reverse to
I don't think it's inefficient
if it works, I think go for it
yeah it works ofc but its not DRY friendly
and there are a few more bytes it has to read
If you don't find any better solutions, I don't think few bytes of data doesn't make a big difference
and also that's not that much of DRY
yeah but i want dry
then make different class for every use case you need. No need to seperate them
Over the last several years, the way I write CSS has transitioned from a "semantic" approach to something more like what people call "functional CSS."
In this post I explain how I got to this point and share some of the lessons and insights I've picked up along the way.
Hi guys! I am new to web development and just finished a book about web development with django. Which IDE are you using? The book (written early 2021) used Pycharm Community, but i cannot even get started and supspect django functionality has been moved to the professional version of pycharm...
I use visual studio code for django, but also good IDEs are sublime text and atom ect
OK, thanks @elder nebula !
I would recommend vs code as well.
It seems like they made it a bit harder in the community version, but it should work according to forum threads. I'll give visual studio a go, seems to be easier to find youtube videos for it
Thanks Demi
heroku no worky
Latest version of Pycharm requires you to have the professional version for it.
you can write a Django app with any version of PyCharm
Professional just gives you additional integrations that may be helpful
anyone know css lol
don't gatekeep, just ask
That's good to know then, for whatever reason when I tried to use Django with the current community version it told me that Django was for the professional version only. Maybe I missed something
the Django integration is, but the version of PyCharm doesn't affect what code you can write/libraries you can use
it's all Python
Gotcha, thanks for the correction
I use Professional now and there's a Django starter project that you can use
perhaps for Community you can't do that
and need to set up the project manually
which is a inconvenience, definitely
hm not directly related but I'd suggest not calling those x and y
because they might not be if you change flex-direction
Hi, I'm looking for some assistance with my existing eSports web platform. Is there anyone that's interested in this? https://level.gg
from flask import Flask
from flask import request
import base64
import json
#return json.dumps(params)
app = Flask(__name__)
@app.route('/api/login', methods=['POST'])
def getloginData():
email = request.values.get('email')
password = request.values.get('password')
print(email, password)
logindata = {
'email': base64.b64decode(str(email)),
'password': base64.b64decode(str(password)),
}
return json.dumps(logindata)
if __name__ == "__main__":
app.run(debug=True)```
```py
import requests
r = requests.post('http://127.0.0.1:5000/api/login', data = {'email': 'am9obmRvZQ==', 'password': 'MTIzNA=='})
print(r.text)```
for some reason, when I run the above code I get this error
https://paste.pythondiscord.com/zubijaqufa.sql
does anyone know how to fix this?
yes, need help?
requests.post('http://127.0.0.1:5000/api/login', data = json.dumps({'email': 'am9obmRvZQ==', 'password': 'MTIzNA=='}))
and how well does it work with CSS
sends the data as a JSON string.
CSS styles HTML which is a concern of the frontend. Flask / Django are backend frameworks.
makes sense
Sorry to bother you, but since you said you use professional Pycharm I was hoping you could help me with getting JavaScript files/scripts to work
I am adding 2 more buttons, "browse games" and "visit forums". Where is the best place to add them? and also what is there to improve in this page?
Hi there!
i would like to write a django model field for user ids....i want it to generate numbers automatically but i want it to have five digits e.g.
00001
00002
... (continuing)
02345
...
99999
can someone help me out, i'm a beginner
we usually don't write the id field, but it's set to bigauto type so is their another typefield i should be using?
Can I use Django to allow users to download a zip file?
Is it necessary to store the id as a 5 digit number in db? You could always pad it with the required number of zeroes after retrieval. Messing with the default strategy does not seem a good idea unless it is really required and you know what you're doing.
If it is really required you can always define a custom field and change the to_python method to do it.
Yes. The response body can have the zip file and you should have to set a header called content-disposition to something that I don't remember
ehh I'll figure it out I just wanted to know where to start looking in the docs for something like that
Too little contrast between text and background. The background is also very loud and distracting. Reduce the opacity or change it altogether
Look up downloading files using Django :)
ok
Looks like someone in the Django discord already listed all the drawbacks to this strategy
i see...what would you recommend then...if i only want to save the primary key plain numbers in the database...e.g. user1 -> id 1, user2 -> id 2...etc...but i want to give the user roles e.g. user 1 is staff category A so id is "A0001"....that is what i'm trying to do
kindly elaborate a bit
oh ok
class UserModel(models.Model):
name = models.CharField()
@property
def get_role(self):
return f"{self.get_role_name()}{self.id}"
def get_role_name(self):
return 'A' # logic to find the role name
user_1 = UserModel.objects.get(id=1)
user_1.get_role # should give A00001
ohhh...i c...TY, i will try this out
hey, putting this here as this is for a website i am doing. i need to get rid of the ['']. i am very new to python this is my first project in it.
what output do you need?
without the ['']
anyone have any idea to work out this next_id
I think i need sth to access the value of song_id to add it with 1
can you give an example
Yes, you can return a FileResponse in your view
what are you trying to do?
Models have a id field by default
yes, it gives my songs value from 1 onwards
so i want to acess the next_id of a certain song
if a song has id 1
then next_id should be 2
You don't need the song_id field
You can make it a property
but i access my songs using the song_id
would that be random or starting from 1 and onwards?
starting from one
i see
You can do something like this py @property def next_id(self): return self.id + 1
i can just do it with a shell script, i was doing that originally but need to stop relying on shell for everything
aight i will try it
thank you
aka just deleting the string [, ], and '
I want to start displaying something on my templates on and past a start date. I have a model with a start date variable... now I just need to figure out how to compare the date from an object to the current date.
I learned about this... is this correct?
@property
def has_started(self):
return utils.timezone.now < self.start_date```
haven't tried this yet... going to
does not work. I'm not sure how to do printing or logging from a running django environment yet either
you forgot the () after now
it should work
turns out I can't use it
TypeError: can't compare datetime.datetime to datetime.date
I'm only comparing to date... no time, so
usage of @property is correct, you just need to figure out the functions to use
you can convert a datetime to a date with .date()
didn't know that, thanks
now the < > is what is confusing the crap out of me just by looking at it
between the two variables
if I'm interpreting it right:
utils.timezone.now().date() > self.expiration```
means... if today's date is later than the expiration date
expiration is another property I have
and I guess this will be for the start
utils.timezone.now().date() >= self.startdate```
If today is is the start date, or if the start date has already passed
right?
yep, that's what it is
that is confusing to look at man
yeah
I'm gonna put that in comments lol
now, for django template language, how would I do more than one ifs?
if this is true, and something else is false, then go
past start date but not expired
try to put logic
in your view
as far as possible
I guess a really messy way is (if a message expires, don't show?)
{% if SysMessage.0.is_expired %}```
I don't like the look of that though
lol, I figured
so that means maybe I may not have to have those properties then 🤔
@stark storm I think you posted that in the wrong place
@property
def is_showing(self):
return ((utils.timezone.now().date() >= self.start_date) == True & (utils.timezone.now().date() > self.expiration) == False)```
this looks like it'll work. Looks somewhat hacky
Что это?
I don't know Russian...
oo-
you don't need == True and == False
for that matter, you want and, not &
@stark storm Don't post memes in an on-topic channel, and please only use English on this server. You might want to re-read our #rules and #code-of-conduct
Извините за беспокойство, я думал, что этот сервер русский...
translation:
sorry for intrusion, I thought it is a russian server
I wonder how could it be mistaken for rus speaking server 🤔
@rustic sky Из того множества, что есть, мы явно можем запутаться
Ну, я больше не беспокоюсь, я выйду
this phrasing makes no sense in russian. perhaps that's not real russian language
all word engings are wrong, not the right syntax of the phrase at all
perhaps it was made with translator
rough attempt to make sense:
Krys:
with keeping in mind available set of ???, we surely can get confused
I will not bother you any longer, I am going to exit
what's a better way to write that? lol
wait, I feel stupid
or not
yeah, I'm confused
if x == True is just if x
oh, whoops
and if x == False is just if not x
lolol
but
in this case you have like if x > y == False
which, assuming a total ordering, is reducible to if x <= y
the thing with the start date is... making it so that if it starts on that date, it returns True
oh
for that matter
you can consider
defining a separate between function
because that's kind of what you have, right
also
if you don't want to do that
at least
extract the date
into a separate variable
yeah that's probs best
def is_showing(self):
today_date = utils.timezone.now().date()
return ((today_date >= self.start_date) and not (today_date > self.expiration))```
oh
return ((today_date >= self.start_date) and (today_date <= self.expiration))```
that looks somewhat confusing
oh right,
return ((today_date >= self.start_date) and (today_date <= self.expiration))
# > = after, < = before```
that'll help
uh, whoops
fixed that
you don't need
all the parentheses
also
and I would say that "today" implies "today's date"
normally I use today for dates
and now for datetimes
I was worried today would interfere with something (it doesn't)
not sure why, so nevermind
well, I think that's all, so thank you
that was kind of fun, ngl
Python can be fun sometimes for sure
why can't I change the x padding of the title
.title {
color: white;
border: 2px solid gray;
background-color: black;
border-radius: 30px;
text-align: center;
padding: 0px -100px;
margin: 50px 0px;
font-size: 100px;
}
<div class="page-content">
<h1 class="title">PlaySky</h1>
</div>
it fits the whole screen
what do you want to do
im not sure that padding is able to be used with negative numbers
i think it's possible only for margin
Flask-SocketIO: how to pass a variable from app.route to socketio.on?
I want to change the vertical padding. because as you can see its very wide right now
how can i use an app view function on another app (i think it can be done right?)
@elder nebula u are the master here
umm what u mean , btw it seems ez
Heroku makes it p easy
Send a redirect from the first view to the second
bro u created yt clone but how u made feature of adding videos wow bro , keep it up u r my inspiration @eternal blade
Thanks 😄
can u help me btw some guidance and 1-2 problems
The video was a FileField
ohh
Sure, ask it here
yes i know but how exactly
app_name='users'
urlpatterns = [
path('register/',views.register,name='register'),
path('login/',v_views.LoginView.as_view(template_name='users/login.html'),name='login'),
path('order_history/',views.order_history,name='order_history'),
path('logout/',v_views.LogoutView.as_view(template_name='users/logout.html'),name='logout'),
path('password_reset/',v_views.PasswordResetView.as_view(),name='password_reset'),
path('password_reset_done/',v_views.PasswordResetDoneView.as_view(),name='password_reset_done'),
path('password_reset/<uidb64>/<token>/',v_views.PasswordResetConfirmView.as_view(),name='password_reset_confirm'),
path('password_reset_complete',v_views.PasswordResetCompleteView.as_view(),name='password_reset_complete')
]```
"auth / password_reset"
here u have only password_reset
maybe is that ?
Looks like the password reset view is trying to link a URL pattern named password_reset_confirm which doesn't exist
hmm but ig u have been using this only for this
is there any other way for reset password
leaving this?
ig it's the only 1 and best
and we can add template_name also
so it's op
umm
this is auth cez
my main app urls
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('index.urls')),
path('auth/',include('users.urls')),
]```
Try specifying the success URL in password reset
edit in this and plz give gimme
v_views.PasswordResetView.as_view(success_url=reverse_lazy('users:password_reset_complete')
Try that
ohhk
what do you mean by app view function on another app?
do you mean view from another app's views.py?
did you create the custom pages?
Did you build it according to docs or did you use a tutorial?
ohk for me let's skip thatt thing i have 1 more issue
wait lemme show
i have to wrap django in this week
from sunday
django rest framework
if i create any user by my register form it stores password like this so i am not able to login but if i create user through django admin then i can login damn bro
@elder nebula
def register(request):
if request.method=='POST':
first_name=request.POST.get('first_name')
last_name=request.POST.get('last_name')
email=request.POST.get('email')
username=request.POST.get('username')
password1=request.POST.get('password1')
password2=request.POST.get('password2')
print(password1)
if password1==password2:
if User.objects.filter(username=username).exists() and User.objects.filter(email=email).exists():
print('Already taken')
new_user=User(first_name=first_name,last_name=last_name,email=email,username=username,password=password1)
new_user.save()
return HttpResponseRedirect('/')
return render(request,'users/register.html')
it also prints the password see
xyz12345
;-;
You should be using django's UserCreationForm to create the users.
but in that we cant customize our form fully we can only use things like crispy forms bootstrap
umm ik that but idk why we use that
is it necessary to use that forms of django cez ig it's not a good way
Use this CustomUserCreationForm
ohh
for example
from django.contrib.auth.models import CustomUserCreationForm
and in forms.py
same

sad lyf!!
fixed that @elder nebula
def register(request):
if request.method=='POST':
first_name=request.POST.get('first_name')
last_name=request.POST.get('last_name')
email=request.POST.get('email')
username=request.POST.get('username')
password1=request.POST.get('password1')
password2=request.POST.get('password2')
print(password1)
if password1==password2:
if User.objects.filter(username=username).exists() and User.objects.filter(email=email).exists():
print('Already taken')
new_user=User.objects.create_user(first_name=first_name,last_name=last_name,email=email,username=username,password=password1)
new_user.save()
return HttpResponseRedirect('/')
return render(request,'users/register.html')
``` its rule of django when we save anything in user we should do
new_user=User.objects.create_user(first_name=first_name,last_name=last_name,email=email,username=username,password=password1)
not
new_user=User(first_name=first_name,last_name=last_name,email=email,username=username,password=password1)
Op !!!
You shouldn't handle passwords with request.POST.get
it's unsafe
You should use django provided methods for password handling
I think this is very good tutorial on how to create what you want
Free website building course with Django & Python: https://codingwithmitch.com/courses/building-a-website-django-python/
In this video I show you how to:
- Create a custom user registration form using the UserCreationForm class
- Register a custom user model (AbstractBaseUser )
https://codingwithmitch.com/courses
Instagram: https://instagra...
ohh
ok going to watch it rn
bro in this he's using django forms and django forms are like we cant edit fields inside it @elder nebula
for example
{% extends "blog/base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="content-section">
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Join Today</legend>
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Sign Up</button>
</div>
</form>
<div class="border-top pt-3">
<small class="text-muted">
Already Have An Account? <a class="ml-2" href="{% url 'login' %}">Sign In</a>
</small>
</div>
</div>
{% endblock content %}```
here where can i beautify fields
and for example i have used tailwind in my base.html
so when i will use bootstrap here in crispy
trust me it will look
ugly
too ugly
you can use crispy forms when using forms.py and you can also create field manually if you want
no nothing i fixed using return redirect
good
yeah
but now im stuck with another error
ModuleNotFoundError: No module named 'crispy_formsdashboard'
DAMN THE COMMA
IM STUPID
i forgot the comma in installed_apps between cryspy forms and dashboard app
hi ,is it widget tweaks useful in django ?
hi, im trying to deploy a django project through heroku and it isnt working for some reason, im not sure what the error is and what im doing wrong
can someone help me with this
Check the logs
hey @eternal blade i want some suggestions
Yeah
Send it here
bro ohk so i have a e-commerce site
i have functions in it to add files login sign up logout order history and order and stuff and search bar now i want that user can themself become a seller and sell
but i cant get idea umm
should i add another type of thing in User for them or i should make other Model for them in db
@eternal blade
You can use a one to one field
Eg: ```py
class Seller(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
products = models.ManyToManyField(Product) # The products the seller will be selling
no more ideas for now
for some reason heroku wasn't picking up on the procfile so i deleted it pushed that change added it back then pushed it again then it finally recognised it
a bit strange but it works now
It should be test.test_title
<p> Test: {{ test.test_title}} </p>
{% endfor %}```
If you iterate over the query, you will be able to handle each individual item with the for loop just fine.
The first way you did it was fine, but you had {{ testdata.test_title}} instead of {{ test.test_title}}
Yea I don't think so. Go back and try looping over it again.
And share the code + error
make sure that the object returned from the function is the actual queryset
You should be getting an error that shows all this info on your page. Is this Django?
Are you in debug=True?
Ah right.
Yea, maybe flask does it differently then.
Are you returning one item or many?
Isn't get for a single object?
query.all()
so filter it
query.filter(thing="nameofthing")
because a list is iterable, an object is not.
Yes, .get() returns a single object because he's retrieving it with primary key
test_id =1
testdata = Test.query.get(test_id)
looks like me that you are.
you're getting the object with pk 1
so what variable are you looking up by?
test_id?
so query.filter(test_id=test_id)
if it's a varaible
just make sure you pass it in correctly.
are you sure it's called test_id?
if you pass a positional argument to .get(), it will assume that the argument is the pk. So in this case it retrieves objects with the pk 1.
If you want to specify the argument use kwargs
@fair shale show us your model
He's using filter now because he wants a group of objects.
It looks like in flask you might have to do query.filter(Test.test_id=test_id)
Just a recommendation, that these are the types of foundational errors that you should be learning to debug by googling a bit first.
It'll be a better learning experience for you.
Because these are like super basic flask functionality issues.
Learning to debug is a skill in itself.
Did you do a flask tutorial or two?
These would come up in any of them really.
Querying should be pretty basic. Try to get those down.
It's a skill you learn alongside learning to code.
You learn what errors mean, and then how to find errors in your code because of what it tells you.
So now you know that that error is telling you that something is wrong with the variable name you supplied.
So you know where to look for the issue.
At least you hope so. 😄
That's a good one to lookup and read about.
can someone help me here
i'm trying to make a website with flask
these are my init and views files
init
from flask import Flask
def create_app():
app=Flask(__name__)
app.config['SECRET_KEY'] = 'apple'
#to tell flask there are bleprints containing different views
from .views import views
from .auth import auth
app.register_blueprint(views,url_prefix='/')
app.register_blueprint(views,url_prefix='/')
return app```
views
from flask import Blueprint
#blueprint of app
views = Blueprint('views', __name__)
@views.root('/')
def home():
return'<h1>test</h1>'```
from server import create_app
app = create_app()
if __name__ == '__main__':
app.run(debug=True)```
yeah
can you print Blueprint?
k 1 min
I don't know how flask works that much so I'm just going to think out loud here.
should root be somewhere in your views=Blueprint variable?
yeah it printed <class 'flask.blueprints.Blueprint'>
yeah i'm looking at a tutorial to set up a flask based website
link it
and its supposed to be using it
In this video, I'm going to be showing you how to make a website with Python, covering Flask, authentication, databases, and more. The goal of this video is to give you what you need to make a finished product that you can tweak, and turn into anything you like. We're going to also go over how you create a new user's account, how you store those...
im only like 13 min in
Probably good to look at the code. 🙂
I want to build notification feature in my social media website can you guys please explain.
which would be best django channels or asynchronous views or any other package.??
How live do you need it to be?
Since a request is made on any page load, you could just request the notifications anytime they changes pages if you need a low-key simple solution.
I can't think of anything besides websockets/channels for live updates.
how would i go about deploying my flask application on aws?
do i deploy it on elastic beanstalk?
Flask or Django?
What are you trying to do?
hi guys im building a flask app, im wondering how to pass information to my script.js file
or just how to fetch data
ecommerce
I'd personally recommend Django for that (although I don't know exactly what you're doing). Django comes included with a wonderful way to interact with your database and so much more good stuff
And flask in which cases is it recommended to use it?
when u have to make simple apps like todo app any simple proj a simple thing
contact page app
that works
can anyone help with this 
i suck at dev ops sorry bro idk
There must be a tutorial somewhere. That's not just a simple answer. It's a process.
so like
let password = axios.get(
"my_url",
headers: {
"Authorization": "10RH9428HF98R12984HT"
}
);
this would work?
I don't use axios much so if that's the syntax then maybe, sure.
But axios as a tool would work, yes.
Apollo client. I use GraphQL so that's what I've been using for a while.
i see i'll check that out
most of the tutorials are different and i don't know which one might be good. Like am i supposed to use elastic beanstalk or something?
hmmm
I don't know a lot about AWS. I usually use DO. So I don't know either, but it all should depend on what you need to accomplish.
EB probably has a purpose. If you need it, use it. See what the tutorial accomplishes and if that works for what you need.
ok thank you
can I use process.env.NAME to access an environment variable
k thanks
it was fake
axios.get() is using the user's IP address to form the request right?
ok
hmmm nothing is working
my javascript isn't functioning for some reason
<script>
console.log("hi")
</script>
even this won't work
hi all. do most of the pals use flask with boostrap? i see from the tutorials, all use it with that tool, not a static css
{ "code" : "3333", "qty": 1 }
Other requests come up like that but for this one it doesn’t so that doesn’t work
i am not getting your question ??