#web-development
2 messages Β· Page 58 of 1
guys, pro tip:
werkzeug.security or bcrypt?
Hello here
I have a question about frontend frameworks like Angular and React. Sometimes while setting up a project I have to run a server. I don't understand why.
For me, the server is involved only with backend stuff.
Webstuff is sandboxed, server regulates access to the files
gist of it
Browser does not allow access to the filesystem without permissiojn
That is why you need a development server, even for plain html and js
I see
And why is a server only involvedf in backend stuff?
Who do you think sends the files over the network?
And why is a server only involvedf in backend stuff?
@tired root I mean, when coding a website, only the backend is directly related to the server
No?
Serving pure HTML does not even have a "backend"
A Webserver such as Apache is primarily a http server, dynamic languages are plugins that tell it how to handle certain files, nothing else
Ah I see now
My goal is to use Django as pure backend and combine it with React. By using start-react-app command I thought I had to handle two servers, one for Django and one for React.
At least for Production.
You need one for serving django, correct and one for serving the html with js
Run gunicorn in the background, only allow connections via ::1 and have an apache/nginx on front that acts as a reverse proxy with a subdomain
if they run on the same machine
Then do another vhost on port 443 with TLS to serve the user, using the main domain
Run gunicorn in the background, only allow connections via
::1and have an apache/nginx on front that acts as a reverse proxy with a subdomain
@tired root I have to admit that I don't really understand it. I use Gunicorn on Heroku and Whitenoise to serve static files. Everything else is obscure to me.
::1 is the ipv6 version of 127.0.0.1
Gunicorn does the uwsgi stuff and to protect it from bad boys, have apache at the front instead to serve your API to react
or nginx
they can be used as a reverse proxy, fetching the data from unicorn and presenting it via https
or whatever you are using, but yes, you need 2 virtual hosts for that plan π
I think I'm starting to get it. But what is a reverse proxy?
A proxy is normally used to connect to the web for example, in companies. You first connect to the proxy and the proxy acts as your public IP
Reverse proxy is the other way around, the proxy acts as proxy for the gunicorn server to shield it from the public
A proxy is normally used to connect to the web for example, in companies. You first connect to the proxy and the proxy acts as your public IP
@tired root It uses NAT?
No
That has nothing to do with NAT
This type of proxy acts on Layer 7
Idk how to explain it differently. YOur browser connects to the Apache, the apache connects to the uwsgi server, fetches the data and sends it via https
That is a Layer 7 reverse proxy
Idk how to explain it differently. YOur browser connects to the Apache, the apache connects to the uwsgi server, fetches the data and sends it via https
@tired root Ah okay, I understand know
And that is why the uwsgi server can run on localhost, like a db
because it does not need public connectivity
But in the end, do I really need to have to pay for two servers to build the app?
I wonder if it is a common practice.
In this case rent a vps, if you are comfortable administrating that
all this can run on a single server
I just want a React Frontend that will connect to Django through Django Rest API.
But if you want to split your website into a backend with Python and a frontend with react, then yeah, you need 2 vhosts. Otherwise it would make little sense
A vps isn't that expensive btw
But if you want to split your website into a backend with Python and a frontend with react, then yeah, you need 2 vhosts. Otherwise it would make little sense
@tired root I see, It was what I feared the most
A vps isn't that expensive btw
@tired root Yes maybe but for the moment I don't have the money. Maybe later.
It was for a small business. I want to build an online platform for gamers. I achieved the essential without Frontend Framework or API. But I wasn't satisfied by the feeling while using it. It was not as app-like as I wanted.
But thanks for your help, I learned new things.
No problem, but try setting it up at home, as practice
with e.g. WSL
or a vm if you have Windows Pro/Linux
I'm mostly working on Ubuntu
which is better to learn django or flask?
ok which one should i use
Django is more complete, enforces more strict ways to do things, Flask is more freeforms and has a smaller footprint, but you can load modules with stuff you are missing via addons
basically im new to web dev
It's up to you
hmm
Read about it, make a decision
If you are new to webdev, flask is more friendly as it guides you through
But Django is the full package
I suppose that Flask gives you more freedom and flexibility than Django
yeah, I also find that file with the routes very weird
I personally like Flask better tbh
I might give it a try later then. I'm mostly a Django and Node user
but then, I don't handle strict form rules in programming very well, one of the reasons I dislike rust
There is nothing wrong with starting out with flask / sanic / starlette / fastapi
I have a bit of an autistic side π
But if you find yourself redefining stuff django already has, it's probably time to move
For example ORM-like data models
but then, I don't handle strict form rules in programming very well, one of the reasons I dislike rust
@tired root Hahaha I planned to learn Rust someday.
You started coding how much time ago? (Sorry if my English is bad)
When I was around 13. There was this German Magazine, called 64er by Markt&Technik and they always had games as listings in Basic. So I typed them down to play the games and at some point, I started getting it
Around 19 I got my first C++ book
I am 41 now
Impressive, I'm only 21
Eh, I am not that good of a programmer tbh. I am terrible with higher level math. But I manage.
But then, it's just a hobby π
Eh, I am not that good of a programmer tbh. I am terrible with higher level math. But I manage.
@tired root I'm terrible at math too XD
But then, it's just a hobby π
@tired root Cool, It's kinda my job and side hustle
But now I realize that its not the channel purpose
I'll return to my code, thanks again
hey guys
i have an issue
i'm scripting a code with a variable into a flask route
but this variable cannot exists always, it exists only if a "if" is satisfied
but i have to pass the variable into the render_template
the problem is that if the variable exists the program works fine, but if the variable doesn't exist because the "if" is not satisfied, it doesn't work fine because i'm passing an inexistent variable
do you have any idea to fix that?
variable = None at the start of the block
the variable exists and can be checked if it has a value that makes sense
@cloud path
thank you! it worked!
@faint bay I built my first flask app yesterday
It's pretty bad, but I'm proud of it.
@knotty seal I like it ^_^
Aww. Thanks π
CSS hover question: any idea why the first section on the left (legaltech) flickers when the hover effect resolves? both in and out ( www.thecodinglawyer.com )
this is the hover code: ```.frontimg1:hover {
transform: scale(1.05);
transition: 0.4s ;
}
.frontimg1 {
transform: scale(1);
transition: 0.4s ;
}```
How come I'm not able to get into vritualenv from my cmd prompt to vs code?
Hey guys, i did a website that track some covid datas : https://dani75i.pythonanywhere.com/
Feel free to say me that you Think in order to improve it
@grizzled crescent just a small gramatical correction: 'data' not 'datas' ! π
Thx @goonhoon
guys i don't manage to upload an image through flask, it doesn't return me any error but the image doesn't load itself into the folder (sorry my bad english)
this is the function, am i doing something wrong?
def save_picture(form_picture):
random_hex = secrets.token_hex(8)
_, f_ext = os.path.splitext(form_picture.filename)
picture_fn = random_hex + f_ext
picture_path = os.path.join(app.root_path, 'static/profile_pics', picture_fn)
form_picture.save(picture_path)
return picture_fn
if form.picture.data:
picture_file = save_picture(form.picture.data)
current_user.image_file = picture_file
and this is into the route
can somebody that's good with virtualenv's help me in sodium?
Im getting Error 521
with Nginx running and ssl working
as far as i can tell
with gunicorn running
server {
listen 80;
listen [::]:80;
server_name crunchy-bot.live www.crunchy-bot.live;
return 302 https://$server_name$request_uri;
}
server {
# SSL configuration
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl on;
ssl_certificate /etc/ssl/certs/cert.pem;
ssl_certificate_key /etc/ssl/private/key.pem;
server_name crunchy-bot.live www.crunchy-bot.live;
location /static {
alias /home/alevelsite/Kireina-Anime/webserver/static;
}
location / {
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
proxy_redirect off;
}
}```
is my current nginx config
Im not entirely sure how df i trouble shoot this
so nginx is 100% running
and so is gunicorn
yet cf says its not running 
Connect directly to it and see?
god i am of the confused rn
What web host do you have?
Its just on a ubuntu VPS
when I've helped friends out on this, it's hosting provider blocked cloudflare for DDOS activity
because all hosting provider sees is a bunch of HTTP connections from specific IPs only and nothing else
So I would open a ticket with provider and ask about automated blocking
Here is cloudflares IPs
that will do it
How come I canβt get into my virtualenv even though I type workon test (test is the name of my virtualenv)
DNS takes time to replicate and CloudFlare has to wait for TTL to expire
Please donβt yell at me for this question Iβve been having a shitty day so far especially in this ds server π But does anyone know how come I canβt get into my virtualenv even though I type workon test in my terminal window on vs code?
@native tide really sorry but wrong channel :/
normally you do <venv name>\Scripts\activate.bat
Oh cuz I was thinking since Iβm working with django rn I thought web development would be a good place π¬
But where can I ask this question?
I already have a help channel, itβs dormant tho π
But Iβm not trying to advertise it in anyway
Not making that mistake again
Django
Can anyone link me to ressources / explain on how to build choice dependent ChoiceFields ? Drop-Down1 => Select Choice => Ajax Call => Drop-Down2 updates.
All the posts i found didnt help me out.
All the posts i found didnt help me out.
@onyx crane If that is slang for "I couldn't just copy/paste it", then this won't help you either
@tired root wow thats a bit rude :D.
In this example the choices are defined inside the js code. I want to load the related model instances. Its often explained by the country, city example where the city options are reliant on the country choice.
=> choices cant be hardcoded in html or js, but must be loaded from the server.
then do a xhr to load the choices as json and go from there
whats an xhr :)?
XMLHttpRequest (XHR) is an API in the form of an object whose methods transfer data between a web browser and a web server. The object is provided by the browser's JavaScript environment. Particularly, retrieval of data from XHR for the purpose of continually modifying a loade...
Hey guys
What's a good platform to host Django/Flask apps?
Other than Heroku and PythonAnywhere. Few criterias is that I need it to be:
- Scalable
- Cost-effective/Cheap
Small AWS instances can be had for free
can anybody help me understand the tradeoff between using AWS API gateway to call lambda proxies vs writing your own API gateway in something like django or flask or quart and calling hosted APIs written in a similar framework (or maybe even something like rails, just spitballing architectures here)
i know they claim the cold start problem is getting better with lambdas but AFAIK the only win doing it the AWS API gateway way is getting caching for free--is that really worth it? or am i missing something else too
right
im a bit at a loss rn
Currently i cannot access the webserver
even tho nothing is getting blocked by firewall
nginx is running
and so it gunicorn
and cloudflare has the name space
yet im stilling error 512
gunicorn log anything funky?
nop
everything on the webserver is saying its running
ive added cloudflare Ips to be allowed by FW and even tried it with firewall off
does htop say you're near limit or something?
nop
Cf8
What happens when you go to hostname assigned to VPS
If you have containers, spin up Nginx hello world really quick
Itβs also possible something has bound to those ports locking out your true stuff
Hello everyone ,
I want to implement a user profile-page type system where users can go to www. Domain/username and see user info there in django. How could I achieve this?
For now basic profile information
Username
Account creation date
And user inputted data
I want every logged in user to be able to see it , I'm aware I need a protected route for this
yep
then define a profile view with a route in urls.py with something like 'home/<slug:username>' if you want the path to be username
Ok, anything else?
you can use the models.User class in your models.py
and subclass it to extend later if you'd like as opposed to just using it out of the box, which is my recommendation
put the logic for querying relevant data
unsure what your scale is or database choice is, but generally this is pretty symmetric
across those options
write your template first (or whatever your actual static rendering will be) so you have an idea of what you'd like to display, then fill it up from the backend
view may look somethign like
class HomeView(generic.detail.DetailView):
template_name = 'home.html'
model = User
context_object_name = 'user_items'
def get_object(self):
return Item.objects.filter(item_owner=self.request.user)
if you want to use function-based views, it's easy too, but my recommendation is to just use CBV
Alright, thanks
np gl
@uncut spire im gonna try just remove the site from CF
and try access it directly
even tho it was working before originally
i imagine you saw the 512 in browser, did thhe nginx access log reflect that?
or error log?
how can i get the nginx log?
where does the failure occur server side is your first mission
/var/log
somewhere in there usually depending on your config
which log should i be looking at
xD
oh wait
nvm i completely didnt read the big blue text saying nginx
probably start with access
hmmm
do you see a 512 in there
in /etc/nginx/nginx.conf, can you tell me your lines for access_log and error_log
ah ok
?
i very nearly forgot to re-enable ssh after firewall reset
fuck me that could of hurt
i had a breif moment of going "oh fuck i logged out"
your DNS just crashed
Resolve-DNSname : www.crunchy-bot.live : DNS name does not exist```
Resolve-DNSname : www.crunchy-bot.live : DNS name does not exist```
I'll wrap into a loop
well this is another amazing thing to go with this other stuff
I remember now why i chose not to deal with the website deployment on another site xD
if you want to watch yourself and running Powershell
while($true){Resolve-DnsName www.crunchy-bot.live -Server 8.8.8.8;sleep 5}```
BTW, this is technically #414737889352744971 issue
did you rotate your NS away from cloudflare?
its still on CF atm
just pointed the A record towards your VPS directly?
your code isn't open source is it?
I wanted to steal your NGINX.conf and shove into nginx container to see if I could replicate the issues
the code is open source but the nginx config isnt there
you posted it earlier π
legit atm
listen 80;
listen [::]:80;
server_name crunchy-bot.live www.crunchy-bot.live;
location /static {
alias /home/alevelsite/Kireina-Anime/webserver/static;
}
location / {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}```
this is what a friend suggested
hit me with your github
ignore the mess lol
and you use nginx for proxy and gunicorn for actual python
I'm firing up my development laptop now
when you tail the access log, do you see a 512
i get litterally nothing lol
both are apparently empty
ls -al on them, maybe they're piping to stdout or something funky
via some symlink nonsense
let's also try kicking nginx to start this off: sudo nginx -t && sudo systemctl restart nginx
so restarting nginx fixed it?
no
it still doesnt bind to the address
but nginx is just saying nothing is wrong and its running
gunicorn -w 5 main:app
got it
do a sudo ufw app list jusut to make sure you have all apps available
sorry i need to go through the standard dumb checks before anything crazy
its on a flexible cloudflare ssl or whatever
right
so for me its still http (bad ik but just want to have a working https test bed)
yeah no worries, common initial proceedings
but your nginx conf listens on :80
https port is 443 and i get redirected to https when i try your site on http
im not an nginx expert but i need that to make sense in my head, right now it doesnt
his earlier nginx had SSL files
yeah
ah
Hi everybody
i tried setting up nginx with and without ssl cert
shall i add the 443 stuff for nginx rq?
something like ssl on; ssl_certificate /etc/ssl/certs/cert.pem; ssl_certificate_key /etc/ssl/private/key.pem; ssl_client_certificate /etc/ssl/certs/cloudflare.crt; ssl_verify_client on;?
I know Pure sqlalchemy and flask_sqlalchemy which one is better to use with flask? Or no difference?
last i checked it wasnt any diffrent as Cs other some minor functionality diffrences
btw for me, when i did ssl i just had cloudflare on full, so no cloudflare crt
flask_sqlalchemy is probably better integrated
+1 on rabbit's response, you're probably going to wind up retreading the implementation but YMMV
so at some point you have to listen 443 ssl http2; listen [::]:443 ssl http2; no? im for sure missing something here if not
i installed it separately
SRE Face: 
xD
i still gotta make an entire DB orm for this project if this freaking domain doesnt kill me first
full on cloudflare is self signed ssl iirc
ah gotcha
im not sure if i understand this fully
but the way im understanding how flexible works
Flexible means it tries to encrypt but if it can't, it won't
yeah im up for building a container lol
also, why nginx
idek
first choice when deploying it with gunicorn ig
had the most support for it when i was searching lol
this is one fat pythong container
π³
hmm?
<address>/home should be an endpoint
the only dependancies are flisk and flask for python
wait
fuck
did i forget the css framework
not that should affect the original deployment i dont think?
hmm no
you could have API that JS calls to gather the data
somthing like JS calling a python api to get the data to make the charts ig
maybe it just a client side thing and im just trying to shoehorn python into this
π
thank god i havent stopped it using the css cdn atm lol
otherwise it would a rather ugly looking page
xD
before i tried to https it it was alright with it
BTW, this is why git is useful even for config files π
opps
ROLLBACK ROLLBACK!
yeah lol
anyone know much about sockets and integrating some type of socket server with a Flask web server? I don't mean websockets I mean normal sockets.
what's wrong with nginx?
huh?
i just saw a "why nginx" and i'm curious
nothing
but gunicorn is production ready
so if they are not proxying anything out of nginx
@ornate solar yeah you just doing a Flask app.run somewhere? gunicorn is a pretty battle tested
yep
do i even need nginx?
unless you are having nginx host something no
@uncut spire yeah i use gunicorn on my production server but don't want the socket server be able to interact with the flask server
wait are you just running gunicorn in the background? i dont understand your use case then
you want to keep your socket server, i.e. gunicorn, to not interact with a flask server (do you mean development server? this is confusing)
in any case, one would want to create /etc/systemd/system/gunicorn.socket to be something like ```[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target```
then you need ot make a choice of systemd supervisord etc
and run your daemon from there
whats the easiest way to have them interact with each other
nice
@uncut spire i only use gunicorn in my production server
so my dev server is just the simple dev server that flask provides
when you say "them interact with each other" my confusion is what the two ends of that interaction mean to you
do you mean dev server and prod server? they should never really interact
got it running on port 80
i want the socket server and flask server to interact
like accessing the db and stuff like that
CF8, DM?
sure
I'm wrapping up
@ornate solar read https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04 and follow that kinda deal, let me know if you run into trouble
this is something more what im looking for
but im using normal sockets, the client is going to be just a normal python program not a browser so thats why i dont think websockets work in my case but im not really sure
that looks like websockets
"i'm not interested in websocket, i'm interested in websockets with socketio"
jk that just looks like a websocket wrapper to me
im prob just gonna separate the flask server and socket server
so sockets and websockets are different concepts, i recommend reading more about each one
Here's a stackoverflow with some distinctions, for reference:
i got that but all the libs that work with flask are for websockets
i cant find one for normal sockets
do libs like flask_socket and flask_socketio work with normal sockets?
normal sockets is not longer web
I got CF8 his dockerfile but I'll reproduce it here so poundcake can see
FROM python:3.8
WORKDIR /usr/src/app
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY ./ ./
RUN ls -R
ENV GUNICORN_CMD_ARGS="--workers=5 --bind 0.0.0.0:8000"
CMD ["gunicorn", "main:app"]
#CMD ["python3", "main.py"]```
LGTM
@ornate solar so no, a websocket is something someone might use for setting up like a chat or streaming feature in their application, it doesn't relate strongly to the concept of regular ole "sockets." a regular socket is, roughly speaking, a bundle of an IP addr, a port number, and a transport protocol like TCP. in your context, it is more likely that you would use something like supervisord or systemd to manage socket and service files for your application, effectively running gunicorn for you. if you wanted something like chat, you would use websockets in your actual python code, using that connection to send and receive data instead of configuring how your application is run
its just for communicating from my local server at home to my digital ocean server
no browser stuff which is why it has to a normal socket but the only libs out there that work easily with flask are for websockets
what is the purpose of the communication
home automation
so controllers connect to the main ws that is talking to the local server
what data needs to be transferred from local server to digital ocean is what i'm trying tto understand
this is starting to sound like it needs something other than websockets, depending on payload
status of devices on the network
websockets work
for sure, but are likely overkill
but websockets are only for the browser
no?
no, devices can use websockets
n they are not
oh
but you may not need or want something tthat heavyweight
tbf wouldnt a simple REST api work
^this is what i'm trying to understand
websocket is method of transport, it runs over HTTP like setup but it's a socket
like one of my api's can easily take 500 requests a sec and on one of our others it handles 30k+ a sec π€·
it could work but it would be nice for instant communication
what does "instant" mean to you
REST apis can still be "instant"
alot of IOT devices use websockets because it's easy to setup
this is why i was asking about payload size and rate π
also, what needs to be done with said data? does it just need to be displayed?
so the local server would be pinging every 5 sec which would be better to be like .5 sec delay
and firewall/routers are familiar with them
how big the payload tho
not very big
just status, i bet it can just be a string
surely a rest api would work then
that is one option. another option is use something like daphne to serve a websocket if you would like to go that route
isnt a ws a lil heavy weight tho for this
we're trying to get you to the best answer here
agree, sending a string every .5sec or even .1 sec is doable with a simple flask endpoint in a local network if you want to set up the polling for it
but again, really need to know what is being done with said data before recommending any optino
yh
ok
i was thinking of using a socket so the server can instantly send commands to the local server
once again what is "instant" to you
you can use a socket as well--let's finish up what needs to be done with the data
something like {type: cmd, dev_id: 1, status: off}
i feel like REST might be the best choice looking at the size of his data
and the speed needed
i feel like a WS is a lil heavy for just that
the local server would see that its a command, find the device from the device id, and turn it off
but with REST, the local server would have to be getting the main server every second
so, the connection does in fact need to be duplexed. data is going back from computer B to computer A
yeah in a perfect world
okay important detail right there
but u can do that with a normal rest api but it would be slower
and i dont want to overload my droplet
another important detail. what are theparameters of your droplet
the lowest... one sec
1TB of transfer
wdym
looking at https://www.digitalocean.com/pricing/
yeah thats it
ok
so probably use vanilla sockets after all--no websocket needed, no rest API needed, you need to be kinda skinny on transfer just to play it safe
something like ```import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("localhost", 5000))on the client side and
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("localhost", 5000))``` on thhe server side
you need to manage your s.recv and s.send pretty carefully to meet the specifications you gave
yeah i got the hello world working and not am trying to work it with the flask server
why do you need flask
is there no way to combine them
if you're gonna have a flask server you might aswell just have a endpoint and use a REST api
what i'm asking is why do you need to involve flask at all?
python manage.py makemigrations appname this line strictly makes the migrations file (e.g. 0007_auto_20200510_1745.py) and that's it, right? it doesn't do anything else as long as i have not yet run python manage.py migrate?
so if i want to in effect cancel the migration and make further changes to my model, then can i just simply delete that migration file?
i wouldnt just delete them
it can bug out like that
just do makemigrations again after changing / reverting stuff
@uncut spire my flask server has all the auth logic, user management, db stuff
@quick cargo ok ty
so an endpoint on the flask side can sent a command through the socket to the local server
but...
why would you have a completely separate socket server when you already have a webserver running
instead of just having another endpoint
i dont want a separate socket server
ok so logic of exposing home automation software via a non-closed network aside, what it sounds like you want is basically socket-communication as a service, and now we're right back to REST unless you want to do socket-as-a-service in the background or something
it now seems best to just run a minimal rest endpoint as @quick cargo mentioned
So you want a flask server that is also a socket client server at the same time?
yes
you'll need a GET and POST on each of those it seems
i find that inadvisable
but maybe someone has done something similar and please bonk me on the head with your knowledge if that's the case
i wouldnt go through the effort of doing all that
considering it'll probs be slower than just another endpoint
it's just so much less work and you're already running the webserver so I don't see tthe point of it being asymptotically less network traffic
You can use aiohttp and async to make a server that acts both as a socket client and http server
with the rest option, the local server would have to GET some type of new_command endpoint every second
@quick cargo local?
even running on my development server it can handle over 500 a sec without breaking a sweat
no need for async yet, think this is still a wtf-do-i-use 10000 foot conversattion
It depends on how you use it
well it can also be a huge perf boost
but it's not relevant yet in any case i believe
Yup
i just saw yesterday how nice quart can be
It depends
and annoying to scale
On how you use them
if you are gonna go async do quart
Quart does not support many flask modules though
because blocking
Yup
you shouldnt be using flask modules for async stuff because most of it is sync
what about native threading?
why?
what about it
ive got my dev server to use threading to make daemons
Is it python based?
Yes
Tbh if you want multiprocessing and scaling you could just use celery
Or docker/kubernetes
i looked at celery
k8s scaling in awsome
not that any of this helps his original question lol
yh
What does he want to do again?
that sounds like webserver is a proxy
no websockets, he's talking about import socket stuff
^
wouldnt (god forbid) nginx do that for him
n
he says after having 12 hours of litteral hell
I am not sure what a webserver does in this scenario though
that's what i'm sayin
If this is IoT you can use a serverless solution
the webserver would be the interface for the controllers
^
I would make this serverless
^
just cut out the middle man lol
Ya
do them beep boops device to device
dont let me sniff your network traffic lol
it's all one network right? you aint runnin some multiple-network home wifi right?
The only reason a webserver is needed is if the traffic between your webserver and localserver should be encrypted
and you want to create a distribution network
But like thats too much to make to control a fridge and a tv
and even if you want a nice frontend for it, just make an android/iphone app that does everything on the LAN
On React Native
it's not so bad
So you never exit that web based development
@rustic pebble just use your Samsung smart fridge to interact with the server to turn on the tv
it's important to note that we're not just putting you down needlessly @ornate solar , it's just you're shoehorning a webserver in there needlessly from the info you've given us
You will essentially have 3 different servers when you can literally do it in one
Webserver, local server, device server
lel
@uncut spire im looking in designing a home automation system and already have my webserver set up for other reasons. I'm just trying to figure out how to control the system remotely
Why can't your devices connect directly to the web server?
some just can't
What is limiting them?
If they can connect to localhost they can connect to internet as well
I don't know why you would want a chromecast over the internet
It has terrible latency anyways
yeah im just gonna make a simple rest server for the remote connection
Are there chromecast sdk tools?
btw, Thanks @uncut spire @zealous siren I havent got it running on https yet but im gonna sleep and deal with this on a fresh head, Atleast its not dockerized!
π here if it needs some helping
it is dockerized**
What are you making?
im attempting to just move a test server onto https
cuz oauth2
and its proven to be the biggest pain in the ass out of everything including making constants in python
You can forward the domain on cloudflare and get free ssl in 5 mins
what we've been doing
lmao
however it decided to go potato mode
Normal, browser cookies
How you set a cookie?
It depends
For example here I am using a cookie to save the user state so I can know which user just signed in
def callback_wrapper(code, DISCORD_CLIENT_ID, DISCORD_CLIENT_SECRET, URL):
token = get_access_token(code, DISCORD_CLIENT_ID, DISCORD_CLIENT_SECRET, URL)
user_data = get_user_data(token)
res = make_response('')
res.set_cookie('user', data_to_jwt(user_data), max_age=3600)
res.headers['location'] = url_for('index')
return res, user_data
This contains a json web token that came from a dict which contains stuff like user_id and user status
The example above is not a normal login
It is using OAuth2
It is the login with discord implementation
Using services that supports OAuth2 is the safest
I am not sure
I always use OAuth2 as it empowers you to add things like Login with Apple Login with Facebook Login with gmail
np
Ok so im going to aim to get a job as web developer and i want to start with Django. I wanted to ask if there are is anything else i should possibly learn
an entire stack
Well you can learn web frameworks like React, Vue, Angular
node
multiprocessing
web apps
and a db like mongo/postgres
As well as html,css,js
and know how to code outside your framework, too many devs that are lost outside of their framework
I can code in python so..
that'll do it
work through the django docs, deploy a django website to some free AWS or something, know how to deploy and manage a db (do some migrations etc)
just experiment... it's the common theme of successful devs
Im using sqllite at the moment
good enough to start π
Wats apache
apache and nginx will actt as proxy servers for your static content, to put it very simply
you should read about both, they are both widely used
I wouldn't suggest starting with react
Do you already have normal html/css/js knowledge?
Yes
Node isn't really something hard you learn it as you go
I would use Vue if I were to get started on a frontend framework
Yea take it slow and you will get good at it
Once you are comfortable working around components
Then react will seem easy
Im fully commited so ill work on them 5 days a week
There is nothing else to do anyway
Yea haha
O well ill come across ot eventually
Once i spent 3 years on this i hope i can use it for something π
Im fully commited
Well then you got a career possibility in front of you
That is good
Although you will find web development vast
Since you have to deal with way more things that just one language
But django feels like a completely new thing
I have never used, will never use django
I find it very bloated and time consuming
I use React to build my websites
I wanted to use flask at first but chose django in the end
flask is better imo
Sometimes it can get harder working in a team
My friend is doing a course on web develoment but he cant help me unless its with css
@rustic pebble how so
Because you are not allowed to express your thoughts as you want which can make you irritated
I dont even know why i chose to learn python
I origanally wanted to be a software, game developer
Because it is probably dynamically typed, interpreted and easy to learn
Java is so bad imo
But it was so time consuming
Java and PHP are the languages I don't know which I'd shoot first
In their defense they both belong/come from the C-family
Every language is like that there
Php was easier then python but more annoying
php is strongly a server language
python is the second best language for everything
But tbh, at least in my opinion, if I were to start now I would pick Golang
Wat is that
lol no generics
golang is another language
Anyway where can i find a good html template
lmao
literally google
free html responsive template
I have started on a rough design for a metasearch engine
I usually design my own templates
I am making
Ok so thats sorted
kiwi what's this valorant site you're making
no
Well it is a metasearch engine for league of legends
i play dota, is it like dotabuff? stat collection etc?
Time to open that js text book
amazing man
Currently designing it but I will superload it with features
I have like 2-3 months to make it
Before valorant gets released
are you working with riot?
I hope to make a site like that one day
Yea it is not going to be difficult
I expect huge load
I have huge plans for that service
desktop app, mobile app, website
I would love to read your code
I am going to do it on react typescript
so idk how much you can understand out of it
If I opensource it I will probably post it on the opensource channel here
But I am not sure whether I will build anything on python at all
I am thinking of a huge stack.
ReactTS for website
c# for windows app
electron react for macapp
react native for mobile devices
Nothing is impossible when you are coding
And that is what keeps me going
I like putting challenges to myself so I keep me motivated
If I were to stick with the same technologies I would be bored by now
decrypting a properly-encoded one-time pad message otta be impossible π
I dont thibk imma learn the hard language
quickly factoring the product of two thousand-bit primes otta be impossible
Like c++
Technologically impossible or programmatically impossible?
@rustic pebble Why C# on Windows if youβve already built it in electron?
Just for portfolio builder?
Of course. You can build it once in react, for web, then most (if not all) will work wrapped in electron. No need for platform specific versions.
But as a portfolio builder sure why not? Flex multiple skills.
Yeah, I am 18 this will look amazing for internships
π
Iβd appreciate it as a hiring manager.
The more code you can share with me the better.
I canβt give more info but it will be the most advanced meta search engine ever
So you bet this will have loads of code
I have built many things revolving around websites and webapps
I am very confident I can build it
What is your data store? A search engine needs a fast data layer.
I havenβt thought about interns for this summer with the lockdown and such. Hmm. I should probably do that.
Yea , I am planning to intern at a bigger company once I am done
Probably move to US as well
My goal is to study AI but it has to wait for now
Good luck. π
Thanks!
can anyone help me with web development
too late dude
My bad
what
Does anybody have any experience scheduling periodic tasks on Celery (working in Flask)? I have correctly set up a periodic task but the crontab schedule seems to be ignored: instead of running every hour the task runs every 10 seconds:
CELERYBEAT_SCHEDULE = {
"check_istop_hourly": {
"task": "tasks.update_is_top",
"schedule": crontab(hour="*", minute="1"),
"args": ()
}
}
hello anyone here?
whats up
ok so are there any good tutorial on flask
https://www.youtube.com/watch?v=MwZwr5Tvyxo&list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH corey does a good set of YT tutorials
In this Python Flask Tutorial, we will be learning how to get started using the Flask framework. We will install the necessary packages and get a basic Hello World Application running in our browser. Let's get started...
The code for this series can be found at:
https://githu...
goes through just about everything from setting up to database to deployment and ssl etc...
you can use the same principles with your own stuff
no matter what site it is, it still follows the same basic paths
but then
he doesnt cover on using templates from google
or does he
@quick cargo the problem is i have downloaded some templates from google but dont know how to use them
what does your project folder look like atm?
huh?
Hello
Can anyone tell me how to validate a POST request using flask with firebase auth?
@gusty girder normally the folder with your flask project would look like this
yes
by default the static and templates folder are supposed to be in the same folder as the main file
I want to make a backend which serves normal get requests and secure post requests for adding content.
to render some google template its the same as if you did it with that blog example
e.g
def home():
return render_template("index.html")```
but to edit it ive to mess up with the html right
yeah if you want to edit the pages no matter what you do you'll need to learn some html and css
it doesnt take too long tbf
ok
@somber wedge Use somthing like Oauth2 then depending on ur backend lib its fairly easy to implement
Hey guys, I was wondering how can I upload images and post them in my "forum", image should be postablr anywhere in that post, i am looking for some docs or myb tut
Hi all, I'm a data scientist currently working as sole engineer for a company. I'm building a Dash web app, but have essentially no experience with web development.
I have a dockerized dash app that runs great locally, slow as hell when deployed on azure. It uses google vision OCR to get text from data, then performs some NLP on the text. Logs show the function to get the OCR results is a bit slower on the deployed app than the local app (2-3 seconds vs 1 second), but nothing awful. I checked my network tools and it shows a 21 second round trip time (client-server-client) with the deployed app, so that seems to be my problem.
Dash has client-side processing using javascript, which looks like it may be the way to go. My problem is that since I use google vision OCR I need credentials. Can I safely hand that info to the client somehow so that it communicates directly with google cloud? Ideally something that can be implemented in flask.
@vague vigil Sharing credentials in any shape or form with the client app is a big no no. What you can do is create an api route that gets called and executes the function afterwards
Much appreciated, Kiwi. I'll take credential sharing off the table of possible options.
What you can do is create an api route that gets called and executes the function afterwards
This is possibly a dumb question - I really am quite ignorant around this stuff: is this different from what I'm currently doing? Currently I click and drag to select points. When I release the click, it fires a callback that does the following on the back end:
- select pixels within the range of the selected points (box select)
- send that part of the image to google OCR
- receive the text from google
- run the text through an NLP classifier
- create a dash datable from this text
- return the table
It's currently this process that takes ~2 seconds on a docker container run locally and 10-45 seconds when deployed.
where can i get free cool looking templates for flask
@vague vigil why dont u run it on docker then?
where can i get free cool looking templates for flask
??
lol?
Penguin, as Azure SRE for my work, something is rotten, Azure should not be that bad
Hey guys, I just starting learning django few days ago. learned about models, views, templates. i also create a todoapp with create,update,delete functionality . But i am stuck now looking for what to learn next
any advice
@rustic pebble because they want non-technical people to have access to it at a specific URL. Otherwise I'd just tell them to pull the docker container and run it.
It is deployed in a docker container though
here is docker's quo "this program doesn't run on my computer" "hmmm it runs on mine though" thus docker got created
@zealous siren do you know where common network issues might occur? The current URL is public, so no firewall issues that I know of. It's an app service app with a Production 1v2 plan, though I tried Production 2 and it made no difference.
Just to double check on the same image for fair comparison, the same thing that takes 21 seconds on azure is 2.8 seconds locally, using the same container.
penguin, do additional requests go faster?
the first one is obviously getting warmed up
No, they don't. And I currently have it set to always on, so theoretically there shouldn't be a warmup
we have .Net Containers that do 30MS response time
I think I'll try deploying it on google cloud, see if I experience the same issues, and then go from there. If I'm having the same problems it's safe to assume it's something wrong with what I'm doing, otherwise I'll start messing with Azure.
yea, you can install Application Insights for Python
Awesome, I'll give that a look!
Thanks for the help yall.
File "C:\Users\Andre\Anaconda3\envs\Django Development\lib\site-packages\allauth\account\models.py", line 13, in <module>
from .adapter import get_adapter
File "C:\Users\Andre\Anaconda3\envs\Django Development\lib\site-packages\allauth\account\adapter.py", line 31, in <module>
from ..utils import (
File "C:\Users\Andre\Anaconda3\envs\Django Development\lib\site-packages\allauth\utils.py", line 12, in <module>
from django.contrib.sites.models import Site
File "C:\Users\Andre\Anaconda3\envs\Django Development\lib\site-packages\django\contrib\sites\models.py", line 78, in <module>
class Site(models.Model):
File "C:\Users\Andre\Anaconda3\envs\Django Development\lib\site-packages\django\db\models\base.py", line 115, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
Hey, I'm trying to make a discord login for my Django website, following the allauth introduction and I get this.
Discord login uses the OAuth2 schema
flask is for backend web development right
It needs different implementation
flask is for backend web development rigth
@gusty girder Yes
allauth supports discord login, but that error doesent look OAuth or allauth related
@gusty girder by writing the frontend
but then that requires html knowledge right
@thick cove I am not really proficient on django sorry
but then that requires html knowledge right
@gusty girder Yes, javascript as well
if you are writing basic pages you will most likely use basic html css and js
isnt there a way to customize it without html css and js
just add bootstrap π
bootstrap?
yes.
whats that?
isnt there a way to customize it without html css and js
@gusty girder there isn't a way to do this no
You will need to use at minimum html and css for it
that is good idea to start without knowing much of how css work
Bootstrap is a CSS module
ok ill check on bootstrap
it will look like bootstrap
so ill be able to customize the front end part with that
Yes
to do front end, you need HTML/CSS/JS
you write basic html then add bootstrap to make it better without writing your own css
to make modern looking SPA you see today, JS is required
what about templates?
to make modern looking SPA you see today, JS is required
@zealous siren You dont need to make a SPA in order to look modern lol
just start here https://getbootstrap.com/docs/4.4/getting-started/introduction/
since you dont have a basic idea of html css start with that first worry about the rest later
Kiwi, when you make those really "slow" post calls, lack of JS will reveal itself π
or is it like django with the complex stuff?
what are you referring to ?
@zealous siren simple fetchapi does the trick for most things except live updates
Sure and if you don't need it, that's fine
but modern type stuff you see from Google/Facebook will totally require you to know JS
what are you referring to ?
is html complex or is it easy to learn
They are based on modern frameworks
but modern type stuff you see from Google/Facebook will totally require you to know JS
oh
So yes you need state managers, sockets, clusters
like G Mail is JS hell
Gmail is probably socket based
some of it is, yess
html is very is to learn it is not even a programming language
oh ok
so ill learn css,javascript and html after getting used to flask and java
python and Java? going crazy there
you would not need much java if youre trying to get into web
is django backend too?
there is a ton of web powered by java
yes
jsp still exists?
mhmm
JSP might exist, no one outside really old enterprise to hell uses it anymore
