#web-development

2 messages · Page 155 of 1

inland timber
#

hey, can anybody explain to me in short how can a print() function relate in any way to a text contained inside an HTML structure? bc It just feels weird to me, like where's the interpreter in that web?

vestal hound
#

I don't really understand

#

maybe you can give an example

inland timber
#

sure!

#

let's say that I install Flask module, import it, create some function with a route decorator to some address and then initialise Flask's server

#

now, If I open the local address where the server is being hosted, I see the output of the function on-screen (let's say, for the sake of simplicity, that It is a print() statement)

#

so my doubt is, how does the whole process of relating the script where I wrote the function's output with the webpage display of that output?

vestal hound
#

you mean

#

in the browser?

inland timber
#

yeah

vestal hound
#

that shouldn't be happening

#

you mean like you have:

from flask import Flask

app = Flask(__name__)
@app.route('/')
def get():
    print("printed string")
    return "returned string"
#

you see "printed string" in your browser window?

inland timber
#

sorry for the delay, I was making the example so you see what I mean

#

there you go

vestal hound
inland timber
#

yeah It's a really simple doubt itself I guess

vestal hound
#

then that's not a print statement, right

#

that is what is being returned

#

from the function

#

so basically

inland timber
#

yep you're right, that was a misconception by my side

vestal hound
#

a web framework is just a bunch of code

#

that maps routes (URLs) to Python functions

#

those Python functions do whatever and return some data

#

then the web framework takes that data

#

and processes it in a way that web browsers will understand

#

and finally returns it to the web browser requesting it

#

so the cycle goes something like this

inland timber
#

user script -> web framework -> translation of the data for web browser compatibility -> web browser display?

vestal hound
#
  1. web browser visits a page with a given URL (sends a "request")
  2. the web framework looks in its data store for the Python function that will handle that URL
  3. the web framework calls that function
  4. that function does stuff and returns something
  5. the web framework processes that "something"
  6. the web framework sends the processed something back to the browser (the "response")
#

you can look up the request-response cycle

inland timber
#

oh cool, imma save all this

vestal hound
#

it's a fair bit more complicated

#

than that

inland timber
#

thank you so much 😄

vestal hound
#

there are things like content negotiation

#

caching

#

etc.

#

but this is the gist of it

inland timber
#

yeah but for starters this is nice

vestal hound
#

no worries 👋

#

btw just curious

#

are you from India?

inland timber
#

nah I'm from Spain hahaha

vestal hound
#

oh that's interesting

#

I was a bit confused

inland timber
#

why is that?

vestal hound
#

because usually "doubt" is used to mean "suspect" (like "I doubt your intentions")

#

the way you used it was more to mean "question", which is very common among people who come from India

#

like "I have a doubt" instead of "I have a question"

#

just an interesting point, nothing big

inland timber
#

yeah, in spanish 'question' is more like directly asking something without any real interest and I guess I related 'doubt' to the spanish equivalent of asking something with interest, 'duda'

#

😛

#

next time I'll just use "inevitable concern about the topic hereby discussed" lmao that'll be funny asf

vestal hound
#

ah okay LOL

#

yup no worries I understood you perfectly

#

it is unfortunate that English has only one word for this kind of thing 🥴

inland timber
#

yeah :s, well, imma go take a look at that backend mistery, see ya

vestal hound
#

yup, atb! 👋

dusk portal
#

hey is any1 free rn??

nimble epoch
dusk portal
nimble epoch
dusk portal
nimble epoch
#

what is it about?

dusk portal
#

i want tips to learn Django fast

nimble epoch
#

oh ok then

dusk portal
#

and mistakes what ppl do while learning Django

#

give all ur exp

#

to me of Django

#

plz

nimble epoch
#

ok

dusk portal
#

ik flask btw

nimble epoch
#

good

dusk portal
#

ok start

#

im seeing 👀

nimble epoch
#

what i do?

#

tell me whats your problem then ill help you with it

#

i cant give all of my exp

dusk portal
#

ok so i face problem while starting localhost server

nimble epoch
#

oh

dusk portal
nimble epoch
#

its kinda hard you want give all of your exp

dusk portal
#

tell the problems

#

which begginers face

#

and how to prevent

nimble epoch
#

i dont know what to say really. just tell whats wrong i can handle it

dusk portal
#

in short i want to know about how and which problems did all face and how to come up ig i dont want to lose but it seems vast and hard

#

then flask

dusk portal
nimble epoch
#

no its not that hard

dusk portal
#

use terminal and stuff

nimble epoch
#

you mean 127.0.0.1:8000 right?

nimble epoch
dusk portal
#

yes

#

u know flask??

#

its simple run

#

and we can debug errors ez too

#

but in django error comes in termanil

nimble epoch
#

i forgot and trying not to remember

dusk portal
#

thats annoyhing

dusk portal
nimble epoch
nimble epoch
dusk portal
#

should i learrn from docs or videos

#

some says dont learn from videos and stuff

nimble epoch
dusk portal
nimble epoch
#

the best videos outhere is for corey and i think even those videos are a bit complicated for beginners. and yeah something is a bit hard when you want to move to django

#

and if you a beginner and you have any problem with running the server i can guide you to there

quick cargo
#

for web dev

#

i highly recommend some of corey's videos

#
#

he covers pretty much everything you'll need to get started with web dev and python in general

opaque rivet
#

and also 2 scoops of django 3.x, really good for best practices

#

anyone going to djangocon?

nimble epoch
quaint holly
#

ahhhhh

#

i will fucking kill myself if this work

opaque rivet
#

does anyone know if DRF custom field validators just point to the function object?
validators=[equity_is_valid]

what happens in the background? Is it something like functools.partial(equity_is_valid, *args_here)?

inland olive
#

Help with fixing this

terse vapor
#

Just a simple question😅 , how can you add token inside html href?

random spindle
#

hello. i want to learn django i am trying to add some back end functionality to a website i am making but i dont know where to start. I dont really know what django does or how it works so is there a good ressource to learn it

calm plume
random spindle
#

like dont u just create a file called like site.py and thats that

#

and then you import django

calm plume
#

It's easier to make it from the command line, since Django is pretty complicated and it gives you the starter files easily

calm plume
random spindle
#

yeah it seems rlly hard

#

like how long is it gonna take me to learn the basics of it

#

because i already have the css and html done

#

but if i am gonna create project i do i incorporate it with my html and css

#

do i put it in the same folder as where my css and html is

calm plume
#

You put html in the templates folder

#

And css in the static folder

random spindle
#

ok thats good

#

thanks

jade nova
#

Hi guys, I'm new here. I'm trying to create a website with Flask using HTML, CSS and JS. I need help creating a sort of drag and drop area where you can drop one word at the time to compose a sentence (the area becomes one "place" longer every time a word is added). Anyone has some ideas?
I so that drag and drop on HTML is not adviced and I did not find anything simple with JS.

terse vapor
#

So kinda like advanced version of wordtune?

random spindle
calm plume
random spindle
#

i dont think it does

#

but maybe

#

lemme check

#

it does

solid jackal
#

Hi im learning Flask yet but it doesn't work

#

must i make a while thing?

terse vapor
#

it should be if __name__ == "__main__":

solid jackal
terse vapor
#

no problem

median loom
#

what are backends in django and how to use them?

wooden ruin
#

there are libraries that you can use with django that come with their own features, but they are not backends, simply libaries

#

popular django libraries include drf and channels

median loom
#

oh wait... i worded it incorrectly

#

i wanted to use a django builtin for rate limits

#

and i don't really get how to use it

#

and what it is really

shadow nova
#

which is best django or flask ?

median loom
#

depends on the purpose from what i've heard

#

and also the complexity

shadow nova
#

yeah.. but for webD which is most preferred ?

median loom
#

i don't really know

#

flask is simple and can be used for quick projects

#

but is limited when more complex features are needed

wooden ruin
#

it just depends on your preferences

shadow nova
#

okay..

native tide
native tide
buoyant shuttle
#

For some reason Django isn't Inheriting my base file

#

It inherits but fails to inherit load static

vestal hound
#

big part of SWE is understanding tradeoffs.

#

when you’re talking about such high level design choices there’s rarely a single right answer

#

and that’s also a false premise

#

what about other frameworks?

#

Quart, Sanic, FastAPI

native tide
vestal hound
#

Pyramid?

terse vapor
violet briar
#

with flask, should I use

<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">

or should I use

<link rel="stylesheet" href="static/css/main.css">
#

both work btw

topaz widget
#

Anyone familiar with Vue? I have sections of a page that I built independently and wondering if it's going to be a problem if I have one Vue instance per section (multiple for a page).

#

No data is shared between sections.

wooden ruin
wooden ruin
topaz widget
# wooden ruin that might be hard to manage, i suggest just using components or even routes if ...

Yeah, I am talking about multiple Vue apps, i.e.:

var page = new Vue( ...

I'm also using components, but only for markup that repeats itself multiple times in any given section.
I plan on using routes in the future, but all the sections are going to be under the same url (same page), so not sure routes is appropriate.
Thanks, though, and please let me know if you have any more suggestions.

sturdy willow
#

How to ensure the dragged element in selenium is** appended **to parent python ?

#

i meant the drag and drop in selenium

outer apex
calm plume
#

More people can help that way

native tide
#

can someone look into this question I just posted to SO? It's better formatted there than it would be here

outer apex
# calm plume You should probably ask here

Oh, don't really need any help per se. I was just interested about the process, that's all.
I was curious about how the app is structured. Do you have Vue's library installed or are you using the CDN? Do you have individual JS files on each page?
How about building and minification of the Vue code?

outer apex
native tide
#

Thanks this will help

hybrid mantle
#

Hi everyone, any one interested in working on a full stack side project with me, am mostly skilled on the backend need someone to help on the front end with React. I already have the project UI designs. Please DM me

inland oak
#

I am in Django and
accepting some API request
what would be the most cultural way
to get the route of my server
https://domain.com

#

as not cultural, I could extract from request.get_raw_uri()

#

"/".join(request.get_raw_uri().split('/')[:3])

#

but it looks slightly as messy solution

calm plume
#

Usually for a production app, or even in development, you use the npm package. You really only use the cdn if you're a beginner

calm plume
#

However, you can use a tool like React router or Vue router to make multiple pages easier.

inland oak
#

It is incoming request to framework

def user_interface(request):

after dir(request)

['COOKIES', 'FILES', 'GET', 'META', 'POST', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_cors_enabled', '_current_scheme_host', '_dont_enforce_csrf_checks', '_encoding', '_get_full_path', '_get_post', '_get_raw_host', '_get_scheme', '_initialize_handlers', '_load_post_and_files', '_mark_post_parse_error', '_messages', '_read_started', '_set_content_type_params', '_set_post', '_stream', '_upload_handlers', 'accepted_types', 'accepts', 'body', 'build_absolute_uri', 'close', 'content_params', 'content_type', 'encoding', 'environ', 'get_full_path', 'get_full_path_info', 'get_host', 'get_port', 'get_raw_uri', 'get_signed_cookie', 'headers', 'is_ajax', 'is_secure', 'method', 'parse_file_upload', 'path', 'path_info', 'read', 'readline', 'readlines', 'resolver_match', 'scheme', 'session', 'upload_handlers', 'user']

I think I could make the same with

f'{request.scheme}://{request.get_host()}'
#

technically it should be same thing

#

looks better solution too

rapid spindle
#

hi, i'm coding a django rest api, i have a question, is anyone know how to get id, or whatever, like my url looks like /polyrent/modules, but i wanna get for instance id, when I use /polyrent/modules/id, i do not get any id...

nimble epoch
rapid spindle
#

@nimble epoch HyperlinkedIdentityField works for all fields? if i wanna get name, ect?

nimble epoch
#

you want to get fields?

rapid spindle
#

I meant, when I enter polyrent/modules/names for example, it gives only names

#

ect

nimble epoch
#

you can use loop then get index name out of it

rapid spindle
#

i see, thank you

opaque rivet
#

what's the point of having flask forwarding a request to django? that sounds nonsensical

inland oak
#

agreeing with user above

#

this is abosolute nonsense

calm plume
#

You use Flask or Django, not both

inland oak
#

yup. It is like buying a ticket to airplane, but instead of it travelling in train

#

or may be even more humorous. Having one leg in airplane, while second leg in the train

#

urgh. sounds horrific

#

I already wrote the answer

#
f'{request.scheme}://{request.get_host()}'
#

this is perfectly acceptable answer for Django

#

just stop it

#
f'{request.scheme}://{request.get_host()}:{request.get_port()}'
#

better with port

#

more accurate

#

REST

#

it does not matter

#

my question not needed those details

#

as I said, just stop

#

we already found the answer

opaque rivet
inland oak
#
Returns the originating host of the request using information from the HTTP_X_FORWARDED_HOST (if USE_X_FORWARDED_HOST is enabled) and HTTP_HOST headers, in that order. If they don’t provide a value, the method uses a combination of SERVER_NAME and SERVER_PORT as detailed in PEP 3333.

Example: "127.0.0.1:8000"

Raises django.core.exceptions.DisallowedHost if the host is not in ALLOWED_HOSTS or the domain name is invalid according to RFC 1034/1035.
#

according to documentation

#

I will check just to be sure, which host it is

opaque rivet
#

ah no, it will be the server's information

#

i mixed up host with origin

inland oak
#

I will make full check anyway

#

you can't be sure

#

unless it was tested

#

got it.

#

it was actually

f'{request.scheme}://{request.get_host()}'
#

because get_host contains already port too

#

so, get_port was not needed

#

returns server address correctly

opaque rivet
#

good to know 👍

solid goblet
#

is Wix good to make a website?
need a payment system that also takes the users discord ID and adds it to database

quick cargo
#

No wix is not

calm plume
#

If you need a payment system, use a proper backend with a tool like Stripe. Wix does not have a backend

quick cargo
#

Things like that with backend integration and be done in a somewhat reasonable mannor cannot be done with something like wix, weebly or others

#

Or use patreon

#

Which is what most people choose to use for bots

calm plume
#

If you're want to take the time to set it up yourself, something like Stripe would be cleaner.
If you don't want to set it up yourself, Patreon is probably ebtter

solid goblet
#

so i have 0 experience with this stuff, basically i just googled website design, saw wix and started using it, but never finished it because i wanted to make the premium command for my bot first

honestly was just thinking of paying someone to do it for me
unless this can be easily done?
but i have no idea where to start or how to use things like stripe etc

past cobalt
#

Hi

calm plume
#

To make a website, you'll need to use html, css, and js

#

Probably with a Django, Flask, or FastAPI backend

#

Those online website makers are not good

solid goblet
#

i started using wix because setting up the layout and look of the site is very easy, but no idea about the payment stuff
🤷

calm plume
#

Wix is not a good option

#

It doesn't have a backend

#

For html, css, and js, there are a number of online tutorials you could learn from

opaque rivet
#

Wix is terrible

calm plume
#

Wix and weebly are just bad

opaque rivet
#

I've used it in the past too, and it was such a pain

solid goblet
#

is running a website expensive

calm plume
#

Using something like Heroku with Netlify

alpine moat
past cobalt
#

Good night everyone logo_vscode logo_vscode logo_vscode logo_pycharm logo_pycharm logo_pycharm

#

Reply plz

nimble epoch
grave hazel
#

hey could someone please help me here?

#

i've made an api with flask and everytime i run it, it shows me this:

#

is there any configuration i need to make or is it showing me this because i'm running this on localhost

calm plume
#

If you're on localhost, you can ignore that

grave hazel
#

i've turned debug mode off

grave hazel
wooden ruin
#

anyone know how i can deploy django with daphne if i'm using asgi/channels?

zinc parrot
#

I have a javascript question. I have the following code.

const animals = ['Hen', 'elephant', 'llama', 'leopard', 'ostrich', 'Whale', 'octopus', 'rabbit', 'lion', 'dog'];

// Create the secretMessage array below
const secretMessage = animals.map(animal => {
  return animal[0];
})

I'm learning about iterators on codecademy. Why, inside of the map method, are we defining a function animal and then treating animal like a value when we index it? It's confusing to me that animal seems to be acting as both a function and a value

naive crater
zinc parrot
#

@naive crater Thanks, and I appreciate the connection to lambdas in python. That is totally weird, but at least makes sense. It has been a bit of a trip coming from python where there is really one way to define a function (dunders withheld) to JS where there are at least three ways

naive crater
zinc parrot
#

That definitely helps my brain feel more at ease with the syntax

naive crater
zinc parrot
#

Thanks 🙂

#

@naive crater Is there a rule of thumb you use for when to use the normal function declaration function functionName(params){ ... } vs an arrow function?

#

vs assigning an anonymous function to a variable

naive crater
#

if I'm just passing it into an event listener once or something, then I'll use an arrow function, but if I'll be reusing it then I'll define it normally

zinc parrot
#

Ok cool thanks.

calm plume
zinc parrot
#

Thanks 🙂

grave star
#

Can someone help me understand xpaths? Specifically, when I use selenium and input in the terminal:

Building = driver.find_element_by_xpath("//*[@id='span_tab_1']/table/tbody/tr/td[2]/div/a")
Building.click()

it works fine. but when I run "Building.click()" again I get the following error:

selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document

BUT!!! if I press the up arrow key twice and reassign using the same the xpath, and then use "Building.click()" again, it works. I'll accept "it's a selenium thing" as an answer, but if there is something else going on in the background of the web page I'd like to know. Thank you!

opaque rivet
#

can celery not run async/asyncio functions?

quick cargo
#

no iirc

#

or atleast

#

not by default

#

and if i remember celery is thread based which causes alot of issues with asyncio

opaque rivet
#

oh I see, because I'm getting the error: 'channels_realtime_price' was never awaited result = (True, prepare_result(fun(*args, **kwargs))) so it's calling my functions and just getting a co-routine object back.

#

is it possible to call asyncio.create_task within sync functions?

quick cargo
#

err yes but actually no

#

it depends if the thread has a running event loop or not

opaque rivet
#

tried to do it in my celery task - didn't work. also tried to start an event loop (within the same function) but that didn't work. guess it's sync functions for me.

#

I have no clue (still) how asyncio can run concurrent tasks within the same thread on a fundamental lvl, is that an issue?

quick cargo
#

err sorta

#

if you intend to use asyncio then i would recommend getting to grips with the ideas it uses to work

#

e.g. co-operative multi-tasking

opaque rivet
#

big thanks 👍

native tide
#
import socket

server= socket.socket()
server.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
server.bind(("0.0.0.0",8080))
server.listen()
cl,addr = server.accept()
print("Povezao se Klijent",addr)
zahtev =  cl.recv(5000).decode()

print(zahtev)
#

why am i getting a "'utf-8' codec can't decode byte 0xfc in position 8: invalid start byte" error

#

when the guy wich wrote the same code on yt worked perfectly

thorn nexus
#

I am trying to build HTML string with data returned from database like this:

res = get_object_or_404(MyApp, id=id)
html_text = ""
html_text += "<h1>" + res.field1 + "</h1>"

How can I clean res.field1 if it is not coming in a POST request? Is there a generic alternative to cleaned_data that I can apply?

native tide
#

i fixed it i had to type port 8000 btw why does that only work on that port

upper trellis
#

The Pallets team just released Flask 2.0! (and Werkzeug 2.0, Jinja 3.0, Click 8.0, ItsDangerous 2.0, and MarkupSafe 2.0) Spread the word on Twitter: https://twitter.com/PalletsTeam/status/1392266507296514048 and Reddit: https://www.reddit.com/r/Python/comments/nacc83/new_major_versions_of_flask_jinja_click_and/

New major versions of all the Pallets Projects have been released! Read our announcement and the changelogs, and try them out today! https://t.co/WJ8GB3uISW

Flask 2.0 🐦
Werkzeug 2.0 🧰
Jinja 3.0 ⛩️
Click 8.0 🐁
ItsDangerous 2.0 ⚔️
MarkupSafe 2.0 🛡️

#

I'm taking a break now, it's been a long day, but I'll check for questions there and here tomorrow. 😄

calm plume
#

Thanks for working on that!

kind steppe
#

super neat stuff. async views and callbacks is great, and I'm a fan of the @app.post and @app.delete decorators as well

indigo condor
#

hi

wispy quail
#

@quick cargo see the async stuff above.

#

async def ... supported

inland oak
#

Awesome!

#

I guess we can throw Quart away now

native tide
#
    <button class="dropdown-button" onclick="dropTheMenu()">MORE ▼</button>
    <script>
      function dropTheMenu() {
        document.getElementsByClassName("dropdown-menu").style.display = "flex";
      }
    </script>

im trying to change the display to flex when someone clicks on the button.

modern anchor
#

I'm planning on doing a large project , so I decided to deploy backend services as microservices , because I wish to scale it in future so it will be easier if each section of backend is separate

Should I use docker or kubernetes ?

and I've never done a project with microservices , so should I host every microservices on a different server or just run multiple docker or kubernetes containers on a single server.

native tide
#

idk

#

it doesn't work in a button?

nova nacelle
#

Probably no, use a div

native tide
#

ok

median kraken
#
.nav-menu .drop-down > a:after {
  content:"\ea96";
  font-family: 'Kanit', sans-serif;
  padding-left: 5px;
}
.bx-left-arrow-circle:before {
    content: "\ea96";

These are in 2 CSS files

<li class="drop-down"><a href="#"><span>Drop Down</span> <i class="bi bi-chevron-down"></i></a>
```HTML file^
https://cdn.discordapp.com/attachments/818357355304845362/841928938360012830/Screenshot_2021-05-12_at_12.14.57_PM.png
There, as you see, no image - the arrow does not appear
Any idea why?
inland oak
native tide
nova nacelle
#

BRUHH use a div wus just an initial advise

native tide
#

:*{

modern anchor
inland oak
#

I don't know a lot about it, but the point is with easy deploying

#

4 replicas can be auto deployed at the different machines

#

you aren't tied with your scenario to one machine

#

this is sort of opposite to scalability in height

modern anchor
#

Thanks🙌

inland oak
#

this is one of examples

#

supposedly there can be other uses

#

I just know only this one)

inland oak
#

for example your application needs additional services

#

Redis and e.t.c.

indigo gale
#

how can I get returned data from AsyncResult object in celery

inland oak
#

Probably kubernetes scenario can automatize stuff like that too

#

to deploy a whole pack of what your application is needing in terms of different containers

#

in one pod

#

and the pod is then replicated

modern anchor
inland oak
#

that's up to you, how would you setup your db

#

if you want it to be shared, it will be shared

#

Kubernetes gives you full control to make whatever devops you wish

#

to scale your application in your way without dependency on your VPS/server provider

modern anchor
#

Ok 👍

minor sedge
#

does django does the same job as js ?

#

_ i know that sounds so silly _

nimble epoch
minor sedge
#

js is web application afaik, what does django do ?

nimble epoch
minor sedge
#

what about flask

nimble epoch
#

backend

minor sedge
#

is there any python library that is for front end ?

nimble epoch
#

im not sure

minor sedge
#

quart is backend as well right ?

nimble epoch
#

i dont know really

minor sedge
#

ok

nimble epoch
indigo gale
severe folio
#

Hello I am new to this channel and I have one question in wich Python module you work?

hardy lotus
nimble epoch
valid prairie
quasi relic
inland oak
#

Not sure how goes situation if you need additional js libraries though

#

Probably npm should work

inland oak
calm plume
#

The \ea9 part

#

As a general rule of thumb, content goes in html, while styling goes in css

median kraken
#

Thanks anyways

solid goblet
#

so yesterday i was asking about website hosting and creating a website
learned all the bad things to do 😄

anyone here use ionos? is this good to use?

calm plume
#

What do you want to do with the website?

#

Use a website builder, or just buy a domain?

solid goblet
#

well ionos offers both i guess

#

but, building a website with payment systems to use with a discord bot with premium features

prisma nebula
#

Do any one know how to link an HTML file to CSS file in visual studio code

calm plume
prisma nebula
#

yeah

calm plume
#

In your <head>, do <link rel="stylesheet" type="text/css" href="path to css file">

#

For example, ```html
<head>
<link rel="stylesheet" type="text/css" href="index.css">
</head>

prisma nebula
#

Thanks for helping

inland oak
#

Giggles. Dunno how much efficient this writing

#

but...

#

with simple js

<script>
    fetch('/server').then(function (response) {
        // The API call was successful!
        return response.text();
    }).then(function (html) {
        // This is the HTML from our response as a text string
        document.getElementById("demo").innerHTML = html;
        console.log(html);
    }).catch(function (err) {
        // There was an error
        console.warn('Something went wrong.', err);
    });
</script>

<p id="demo"></p>
#

I could use my django

#

to render stuff while getting extra stuff from API endpoints!

#

it has potential for a smooth front I hope

#

I could try putting inside API stuff, pre rendered by Jinja template!

#

it should make my front logic quite simple

dry arch
#

I have a FastAPI project with the follow structure:

Project
- app/
-- __init__.py
-- main.py
-- database/
--- __init__.py
--- db.py
--- models.py

Inside main.py I want to import the models from models.py as well as some functions from db.py.

When trying to import like this:
from app.database.db import functionA, functionB I get an error no module named "app" . I've tried some other ways of import as well but I don't really understand how the packages/modules in python work when nested like this.

Can someone help me with this/help me understand so I can start doing it correctly?

opaque rivet
inland oak
#

and well... the general goal of the web site is making quick navigation through the database of tables

#

quick rerender with javascript should make things much nicer experience for users, than full re render

opaque rivet
#

yeah - that's right, but are you re-rendering the whole webpage or just modifying a DOM element?

inland oak
opaque rivet
#

ah gotcha. I thought you were moving from server-side rendering to client-side

inland oak
#

actually this is interesting to try as well

#

perhaps rendering the main table with JS too

#

I'll have at my server side it fully prepared, pre-rendered with Jinja

#

leaving at client side only to pull it

#

I'll think about it later, for now I'll pull with JS only secondary table

#

which I could not be rendering smoothly without JS at all

opaque rivet
#

agreed, that's why frameworks like react have all of the appeal 🙂

inland oak
#

I am not ready for React yet I think

quick cargo
#

react is very easy

inland oak
#

learning how to do this stuff semi manually should be better experience for me for now perhaps I think

quick cargo
#

if you can read a little bit of JS and write a function in JS you can do react

lofty sigil
#

Do browsers automatically set X-CSRF-TOKEN if we just supply the csrf-token as a cookie?

I am using flask and flask_jwt_extended seems to set some csrf token cookies which it expects as headers to validate further requests.

opaque rivet
#

yeah React is easy, most of the learning will be done learning third party libs. like redux etc.

inland oak
#

I did not try React yet
but I already learned how to deploy it%

#

our front ender did not know how

opaque rivet
lofty sigil
#

Ooh, Thx!

#

I was using post man and dying to understand why it was happening 😓

inland oak
#

Considering that this current project I do mostly out of learning.
I'll probably first will make JS/Jinja render
and re learn how to that in React after that

#

it will give chance to compare which way is easier

opaque rivet
#

i recommend it highly

inland oak
#

If I'll be able keeping my code dry as it is
I'll have only two JS functions.

  1. Pull main table of the current section
  2. Pull secondary table based on selected row in the first table
#

it should be managable without react

opaque rivet
#

yeah definitely

native tide
#

How to make stateless files in NodeJS like with PHP which is deleted at the end of each request without creating caching problems via modules or exports ?

quick cargo
#

errr you sorta cant

#

PHP and NodeJS differ in their execution alot

#

and Node and the JS system in general is not designed to do that

native tide
calm plume
#

In your case, Node.js may be useless, yes.

quick cargo
#

if this is for a static site then yes

native tide
#

At the beginning, I wanted to make a site in PHP, the problem with PHP is that the types have problems and that there is no asynchronous and the calculation in PHP is slow

I went to NodeJS, I feel trapped

I don't know if Rust / Go will have the same problem if ?

calm plume
#

If you want to use Node.js, you should use a JS frontend usually.

quick cargo
#

well

native tide
#

I have the impression that doing a simple MVC in NodeJS is very complex

in PHP it becomes easier but PHP has many problems

calm plume
#

PHP and Node are both used for backend, so there's really no point in using both (unless I'm confusing PHP with something else)

quick cargo
#

You might wanna explain what your goal is here a bit better

#

Rust, Python, Go, NodeJS etc... can all do the same thing

native tide
#

My goal is to make a simple dynamic site with NodeJS

I came here because I had a problem with the requests since it keeps cached via the requires of the old request

If there is a new request, it will be impossible to retrieve the current request since I stored it in a class via export.request = request or module.exports = request

#

I have to do a request.reset() at the end of each request to empty the attribute in the Request class

I don't know, if there will be a problem when I have a lot of requests at the same time

quick cargo
#

I just wouldnt do that

native tide
#

So if making a simple site in NodeJS is complex, then making an API / API Rest in NodeJS is complex too

calm plume
#

APIs can be (relatively) easily made using express

quick cargo
#

Well if you want some global var stuff (which you really shouldnt do) you might wanna consider Flask with python

#

but generally, you avoid and shouldnt use globals as much as possible unless they're constant

#

the reason PHP can get away with the global and changing state is because it's directly synchronous so it can correctly handle the global state without invaliding it

#

with asynchronous logic its a very very dangerous game

native tide
#

I do not want to use a framework whatever the programming language used

I wish to do everything since the native language

#

In some cases, I need to do Asychrone, Pipeline, Stream

PHP is a bad programming language, it's cruelly lacking structure, other languages have good structures

quick cargo
#

you want to write all the framework stuff yourself?

calm plume
#

If you dislike PHP, why are you using it?

native tide
#

Yes I want to use without framework myself

I no longer use PHP, it was at first to test the possibilities of this language, I selected negative points when I want to do things

calm plume
#

So which language are you doing it in then?

quick cargo
#

Do you want to use it for production?

native tide
#

After, I'm a big fan of Python, the same python is slower than php, I'm disappointed

quick cargo
#

if yes, I sorta gotta recommend against it

quick cargo
#

cuz like most stuff on the web, the slowest thing is the IO not the language

calm plume
#

Python is plenty fast enough for most things. Unless you're doing something that needs speed, then Python should be good enough.

native tide
quick cargo
#

then i can only recommend against making the framework and socket interactions yourself really

#

Production grade HTTP servers and frameworks are HARD

#

there is so much logic and behavior as well as security you need to get correct in order for it to be production ready

native tide
#

If language plays an important role, for algorithms

calm plume
#

May I ask why you don't want to use frameworks/packages besides the core language?

quick cargo
#

trust me im on iteration 3 of my webserver and framework just to correctly support HTTP/1 + be secure + be efficient

native tide
#

I hated the frameworks, it's bad programmed, their programmed way scares, too much calculation for nothing, too much line of code for nothing, no structure etc etc, "we can not make the generality only by making case by case and not of the generality to make the case by case "

calm plume
#

Express is a very good framework

#

If you want to make an API

native tide
#

I wish to create my own stuff, it's safer in terms of performance, structure, logical

quick cargo
#

I can guarantee that the existing frameworks that have existed for a while, will be better coded than what you can make, not to insult your coding ability but its just they've existed for longer, have hundreds of maintainers, security patches and thousands of tests.

#

As for performance it's really not

#

the language performance or framework execution performance in reality means almost nothing when everything is setup because IO takes time, databases take time etc...

calm plume
#

There's just some things that can come from hundreds of people working on a project that one person simply can't do.

native tide
#

Try to make algorithms and you will see a big difference in terms of performance, try to do less code line and you will see

If we use frameworks / solutions all done, we can never understand the real problem

quick cargo
#

Sure, but algorithms are alot diffrent to production grade frameworks lol

#

and also algorithms are generally CPU bound problems

#

not IO bound

#

if you have a server that can handle say 7,000 req/sec (doesnt sound like much) you get hundreds of BILLIONS of requests a year with that

native tide
#

I have no problem with the CPU or anything, my only problem is the language that is limited to keep information and is eliminated at each end of the query, a bit like PHP logic, that's Well, I'm trying to do this kind of logic

quick cargo
#

Well dont if you want it to be asynchronous

#

because that's how you run into state invalidation and race conditions

#

as a warning though Premature optimization will be the death of your project if you dont think about other things first

#

because Fast != good, maintainable and secure

native tide
#

So the number of request per second is a big debate, I managed to test up to about 500000 queries / seconds

Asynchronous perhaps interesting for IO

quick cargo
#

okay sure

#

but you wont ever get that in reality

#

and if your db gets hit that much then your setup is wrong

#

even 7,000 req/sec equates to billions of requests over a year

#

which is the size and scale of some of the largests websites in the world that run thousands of servers

native tide
#

I do not optimize premature, I'm testing, I do my features and I see how I can improve it

For databases, there are replicas as well as other solution, after all depends on the need

quick cargo
#

shrug Sounds like its premature optimizations to me, but hey sure your site might be Wikipedia level big with thousands of servers and your databases are so hyper optimized that they take nanoseconds to get data and the framework and language is absolutely the bottleneck

native tide
#

What worries me in the web is that the pages are slow and the weight of the pages are heavy, we are on average to more than 2 MB per site page, there is a big problem

quick cargo
#

and guess what :P thats nothing to do with the language or framework

#

and web pages will only continue to get bigger

#

because sticking static apps like React and Vue which client side render and can be served globally on CDNs is considerably easier than server side rendering and scaling and browsers are getting quicker to render them

#

New tech like webrender makes most CSS performance tricks obsolete now lol

calm plume
#

If your pages are more that 2mb, that sounds like a problem, unless you're in a special scenario

quick cargo
#

oh yeah

#

most pages are not 2MB though

#

maybe in total with every page loaded with assets

native tide
#

I quote 2 MB who is an average, I generalize? so there are advantages and disadvantages when using frameworks / languages

calm plume
#

I still don't see the disadvantage to using a framework

native tide
#

I do not have a bottleneck, since you talk about it

quick cargo
#

saying that even with that my entire webpage which is a all in one site transfers the entire page in fractions of seconds with lazy loading with kb chunks

native tide
#

Your pages are compressed ?

quick cargo
#

pfft no

calm plume
#

Lazy loading is super useful

native tide
#

that's a first problem

quick cargo
#

how so? We dont need it, and for the size of compression its not worth it to us or the user

#

It takes < 100ms to load everything

#

on a site that is very much not optimised

native tide
#

For a blog, personal site, we can not care about performance, however for a professional site it's important to be efficient and optimized

quick cargo
#

then use a professional grade framework dont try make your own that will be unbattle tested, lacking in certain areas etc...

#

If our framework on clojure which runs at the same speed at python can handle the some 2.5 billion row + database and millions of monthly requests

#

I dont think the framework matters bloblul

#

and if you still dont believe that look at some of the big sites like Instagram, Discord etc... that still use Django and Flask which even in python are considered 'slow'

#

cuz in reality like i say

#

the framework isnt the slowest thing

native tide
#

I simply adapt to my problem, it's not really a framework that I'm trying to do

I have already used frameworks, I am very disappointed with the way it is programmed,

Frameworks pollute the web and computer when it's badly designed

quick cargo
#

So you're basing your opinion of all language's ecosystems and frameworks on one other language pithink

#

(even though those frameworks still power some of the largest sites in the world and have been battle tested through most of the web's life)

calm plume
#

And you're saying you can do better than something that hundreds of people that have contributed to?

#

If so, go right ahead.

warped heart
#

anybody know how to fix or disable STRICT MIME TYPE CHECKING on django. It doesnt allow me to apply any CSS Style sheets or use any .js files

#

and yes in all my tags i use type='text/css' etc.

native tide
#

Honestly, for years that I'm looking for simple and innovative solutions and it works, I do not finish everything but it's good

I am convinced that my solutions will work, it remains for me to pay the stairless query story as php logic

quick cargo
#

can you share the meta tag block and the error?

burnt raptor
#

Hi All, I have developed a game using pygame. How can I host it on a website? I am planning to use Heroku.

quick cargo
#

Websites are a whole other ecosystem to native type games like pygame

#

whole other ballgame

#

if you mean just like, make a website for it and people download the code then yes its possible

burnt raptor
#

I was looking at libraries like pyjsdl.. would it work?

#

any other alternatives instead of pygame to make it run on website?

warped heart
# quick cargo If this is coming from the browser which i assume it is, then it's an issue with...

error from browser console

Refused to apply style from 'http://localhost:63342/static/index_assets/vendor/bootstrap/css/bootstrap.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

html tag

<link href="/static/index_assets/vendor/bootstrap/css/bootstrap.min.css" type="text/css">

django

return render(request, 'index.html')

## render = django.shortcuts.render
#

django responds with 200 so i assume its just the browser

quick cargo
#

its the browser yeah

#

can you send the full meta tag block

#

/ where is the html tag

quick cargo
#

unless you want to re-write it all in browser JS or explore the wacky world of web assembly stuff with another language like C, C++, Rust, Go etc...

#

Python doesnt compile to wasm though

warped heart
#
<head>
  <script data-ad-client="ca-pub-2387817887649725" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <script async src="https://arc.io/widget.min.js#orJQqvxn"></script>
  <meta name="theme-color" content="#f54646">
    
  <title>Home</title>
  <link href="/static/index_assets/vendor/bootstrap/css/bootstrap.min.css" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Catamaran:100,200,300,400,500,600,700,800,900" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Lato:100,100i,300,300i,400,400i,700,700i,900,900i" type="text/css">
  <link href="/static/index_assets/css/one-page-wonder.min.css" type="text/css">

</head>
burnt raptor
burnt raptor
#

Can I install pygame as android app may be?

quick cargo
#

not really

#

you want something like Kivy for that

warped heart
#

it loads everything fine with debug set as True

quick cargo
#

oh wait

#

when you set it to false

warped heart
#

yes then stuff breaks

quick cargo
#

you are using something like nginx to serve the static stuff dont you?

#

not just use the debug server

calm plume
warped heart
quick cargo
#

ah well

#

when Django is in production mode (DEBUG=False)

#

it doesnt serve static content

#

because in production you a) shouldnt use the debug server to run django and b) python shouldnt serve the static files

warped heart
quick cargo
#

performance and security mostly

warped heart
#

o alr

#

thanks

quick cargo
#

basically i'd keep to using Debug mode till you're ready to deploy

#

then collect static

#

then stick behind a reverse proxy and let it serve the content

#

take a look at corey shafer's videos on Django and deploying it 😉 Should work a treat

warped heart
#

thanks

#

will do

native tide
# calm plume If what you're doing works, is there a question you have?

I separated the operation after I gather everything to see how it will react

It is this query story that does not delete in the end and can be mixed with the old and new request of another user, the problem is complex,

I am trying to do the same functioning of the requests that php that there I find interesting

quick cargo
#

(and you're trying to do that in a asynchronous runtime where the state cannot be guaranteed to be in the correct context for each request)

#

just as a addition to that note :P

meager sand
native tide
meager sand
#

I'm now using Traefik for reverse proxy & ssl termination instead of nginx, but traefik doesn't serve static files

#

while it would be possible to have nginx behind traefik I guess but idk if that makes sense

#

whitenoise seems nice, on the other hand it's not asgi-ready

#

(but should be soon)

quick cargo
#

Welcome to the JS event loop setup :P

#

whitenoise seems alright

#

though it's not something i would still use just because Nginx is just so hyper optimised

#

not that python cant do as well, but unless it's using os.sendfile it'll struggle

quick cargo
meager sand
#

I haven't heard of it

quick cargo
#

Ditch traefik return to monke

#

Kong is basically a framework build around Nginx

meager sand
#

I wanted to ask whether it would make sense to have nginx behind traefik for static content, I'm such a web noob that I cannot tell

quick cargo
#

so nginx does all the heavy lifting but kong gives you all the pro's of traefik

#

Personally i prefer kong because it requires less nonsense configuration like traefik and it doesnt try shove paid features all the time

native tide
quick cargo
#

has a nice open source web ui aswell

quick cargo
meager sand
#

the immediate downside to konga is that I'm googling for information and getting pictures of monkeys 😔

quick cargo
#

aha

#

google Kong Gateway and Konga Dashboard i think

native tide
meager sand
#

on the other hand traefik resolves to the pesky gopher

#

so I guess it's not much better on that front

quick cargo
quick cargo
meager sand
#

thanks 🙏

quick cargo
#

By far the nicest thing is you dont have to deal with traefik's setup of using labels etc...

#

you can live reload extensions, built in proxy cache etc...

meager sand
#

I don't know, I found traefik very pleasant to work with

quick cargo
meager sand
#

but I deploy to kubernetes using a pre-made helm chart so maybe that's why

quick cargo
#

I'd definitely recommend giving Kong a go 😅

#

Personally i prefer it, I know others will swear by traefik

#

but generally a avoid software that tries to pressure you into their cloud enterprise setup for stuff that doesnt need it

meager sand
#

yeah I probably will I haven't touched web much in the past so trying loads of different things is beneficial to me right now anyway

#

if only for the purposes of learning

quick cargo
#

tis the best way to learn

#

try everything

meager sand
#

😌

quick cargo
#

now back to my UDP hell lul

native tide
#

Otherwise I have an idea, how do you make to reduce the request information from another file without going through arguments (req, res) ?

quick cargo
#

do it though arguments

#

they're free

#

use them

native tide
#

Okay so that I have to go to all my functions (Req & Res) by avoiding stored in a Class that can be reused later then

opaque rivet
quick cargo
#

rust

native tide
#

hello, is twisted still widely used or was it replaced by something in recent years?

#

My game dev book from 2004 recommends twisted

violet briar
#

I got a question about flask, when the user tries to login and the server finds that their input info is wrong, how do I make the server tell them their info was wrong, how do I make the server push a label into the HTML document saying "invalid login info"

wooden ruin
violet briar
#

doing all of it by hand

#

oh, wait, I found a way, I make a variable called "wrong info", if the login information is wrong that variable gets set to True and gets passed to render template, so jinga has an if statement block with the "wrong login information" label that gets activated if the variable is true

terse vapor
#

oh, nvm

prisma ferry
#

hey so im making a discord login for my website

#

and i have some issues with oauth2

#

it keeps giving me a keyerror for some reason

#
OAUTH2_CLIENT_ID = os.environ['839258071439900733']
  File "D:\Python 3.9.1\lib\os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: '839258071439900733'
#

thats the error

inland oak
violet briar
#

I don't wanna flash messages, I wanna insert an HTML element, because I want it to be styled with CSS

inland oak
#

It is styled too

violet briar
#

how do I style it?

inland oak
#

Question regarding React

#

we have a project already running with npm, build, serve, package.json. It is more or less half backed React project. Full of different npm libraries.
How much of hustle would be attaching webpack to it at this stage?

#

I am unsure if it would take just few minutes or... it would take much greater time

timber glacier
#
    email = StringField("Email", validators=[DataRequired(), Email()])
    password = PasswordField("Password", validators=[DataRequired()])
    remember = BooleanField("Remember me", default=False)
    submit = SubmitField("Login")```
opal basalt
#

could i ask a question for research purposes based on wordpress?

vagrant owl
#

Guys, how do I create some backend python script that checks the formatting(Grammar) of YAML files?

inland oak
hoary brook
#

If it has any errors, it will create the form field with the invalid class which I use to add a red border, as well as show the error message below the form field.

#

I use this since it is nicer for the user to see where the error is instead of flashing everything in one big message at the top or bottom of the screen.

#

In my case it looks like this:

opaque rivet
#

What's the use case of micro-services? In reality, are micro-services just small API sections of a monolithic web-app?

nimble epoch
#

probably cause they are just more simple

opaque rivet
#

I'd say the exact opposite.

inland oak
#

and due to them being splitted into separated small API sections...

#

it can be more easily testable/developed and e.tc.

nimble epoch
#

can they be more flexable

inland oak
#

it can make your logic also more DRY

#

due to one application making it good

#

while other apps use only this one for that

opaque rivet
#

Yeah I'm looking to make micro-services for my next project, I could even incorporate them into my own. I'm just wondering how to go about the devops side of it, how do I start?

nimble epoch
#

sheesh should i move to flask

inland oak
#

miscroservices model is similar to db models in how we think it should be

#

when we think about required db models in SQL, we think about interactions between them with foreign keys

#

microservices model is more or less same in this case

#

you need to think what should be separated, why it would be better separated, and how your applications going to communicate between each other

vagrant owl
inland oak
#

the most often case: we separate web site to backend and front end applications ;b

opaque rivet
#

Well, I've got one monolithic app for data retrieval & visualization. I want to add ML to my project, and then a seperate API for my ML model.

I wanted to move to micro-services to decouple the application and allow for more isolated testing. I feel having everything in one monolith will have less effective testing.

inland oak
#

how many developers do you have on your project?

opaque rivet
#

I'm solo, it's just personal

inland oak
#

not sure if there would be real proffit from microservices then
it is supposed to be good when you have more than one developer

it can bring you good with enforcing better application separation by design though
it can help you if you struggle to structurize your application with separated logic from different sections.

#

i think, if you aren't having struggle to refactor your application/writing tests on your own, then you can go without microservices

#

but as I said I did not read the book yet

#

so I can't say for sure

#

it is just looking to me like overkill to make microservices when you are solo developer

#

microservices can be also used... as better way to scale your application

#

it can be also good then for your even solo usage

#

think for yourself, if you need some part of your application section scaled independently from each other

opaque rivet
#

Well, I have been refactoring a lot recently and although now it's more usable, once I add my ML models and API it's going to be large...

So, if I have my django app serving as my backend - and I want to add a micro service for a frontend feature. Should I make API calls from my backend or my frontend?

Is it normal to have one monolithic app connecting all the micro-services?

inland oak
#

another point of microservices to lessen load on your cognitive resources

#

the less you can keep in mind about one application, then better

opaque rivet
#

But like... should my monolithic app be a "centre" between my micro-services?

I need to read a book on it, idk if I deploy my micro-services if i also need different domains for each API

inland oak
#

your each microservice does only small part job

#

and all results outputed to your front end site

#

there would be nothing monolitic then

#

you are usually having monolith or microservices

#

not both%

#

although nothing forbids from having a mix of them

native tide
#

Has anyone worked with Django & Hotwire, and could share experiences logo_django2

opaque rivet
#

@inland oak yeah, I mean if I have my microservices I need to connect them somehow, so would I have one server handling that?

Also each microservice in this case would be a seperate django server? Or can they all be on the same server

#

Technically, aren't seperate django apps microservices? Or do they have to be on different servers? (So if an exception is raised, only the one server will fail)

vestal hound
#

the idea of a microservice

#

is that it can be stood up and scaled independently

opaque rivet
#

@vestal hound so each project has to be deployed seperately?

vestal hound
#

and be independent

#

okay example

#

Insta

#

you could have an image service and a chat service

#

image service takes care of uploading and viewing images

#

chat service takes care of chat

#

so let's say

#

people happen to be talking a LOT more today

#

you can independently scale up the number of chat microservice instances

opaque rivet
#

I see... so will the frontend make requests to each microservices or will there be a single server which orchestrates all of the microservices? I'm thinking the 1st option.

vestal hound
#

the latter

#

is something

#

called

#

BFF

#

backend for frontend

#

which is a p common pattern

#

in cases where your app is simple

#

or the microservices exist only for your frontend

#

a BFF is unnecessary

#

that's more appropriate

#

for situations where there are multiple frontends

#

and multiple microservices

#

and each frontend consumes a subset of the microservices

#

so an intermediary layer makes things more convenient

#

that also allows you to add, for example

#

default functionality in cases where individual microservices are down

#

that varies between frontends

opaque rivet
#

Yeah, thanks for the know-how. I have a django backend for react frontend, and I was thinking to have that server orchestrate between the microservices.

Do you think I should learn docker before diving into this?

inland oak
#

docker is usually must have for microservices

#

containerization helps for easier deployment and dependency control

vestal hound
inland oak
#

you can go without it, but it would be just less comfortable

vestal hound
#

they all interact.

#

one of the big selling points of a microservice

#

is that you can scale it up

#

stateless containers really help with that

#

so on top of Docker or whatever you choose

#

you have a container orchestrator

inland oak
#

docker compose for example

#

the most easiest
to build it all together

vestal hound
#

having all this managed for you

#

is really nice

#

e.g.

#

EKS

#

or GKE

#

(AWS Elastic K8s Service/Google k8s Engine)

native tide
#

Can you help me to find out how can I use python instead of PHP.
So I have a fully working html, css, JavaScript site and I want to use python to connect for sql.
Thanks

nimble epoch
#

You can use django and django models or flask and flask_sqlalchemy

native tide
#

thanks I will try

nimble epoch
#

yw

distant canopy
#

Hii I am new to the server

#

andd dose anyone know how to make a cname

sleek oar
#

Is anyone aware of where to find part-time volunteer opportunities for working on Django sites. I want to get back into Python and Django specifically.

proud linden
#
Traceback (most recent call last):
  File "main.py", line 3, in <module>
    app - Flask(__name__)
NameError: name 'app' is not defined```
nimble epoch
#

thats clear bro

foggy bramble
#

Hello everyone, I'm learning authentication with token in django rest framework.

I wrote the code and it works when I send token in the header.
But how can i automate this process?
Like once the user logs in, token should be sent in each request

opaque rivet
#

@vestal hound so in production, are each of the containers on seperate VMs? So you can have more/less VMs allowing for more scaling?

How would I setup ci/cd for different microservices, should each be in a different repo or can I have different ci/cd scripts for each branch?

#

@foggy bramble use JS to attach the token cookie to each request

foggy bramble
nimble epoch
foggy bramble
nimble epoch
#

yyeah i think

foggy bramble
#

Do you have any sample code showing implementation of that..?

nimble epoch
#

ok you using frontend?

foggy bramble
#

Because any tutorial i found on the internet is just showing how to create token and send the token in the head using postman.... But what I'm thinking is that users won't use postman and enter the token each time, so we need to automate

foggy bramble
nimble epoch
#

so i dont think that you need token auth

foggy bramble
nimble epoch
#

you use that user token in frontend to show that a user is logged in. i dont say that you cant just say that you dont need

opaque rivet
#

@foggy bramble yes - you need to set a token cookie and attach that to each header. Do not store it in local storage, as localstorage data is only available on the clientside (and doesn't have expiry dates).

#

@nimble epoch Token auth / Session auth - it all uses tokens saved in cookies. I'm not sure what your alternative is.

foggy bramble
nimble epoch
nimble epoch
#

and of course you can use sessionStorage to save it and itll get expired after a time

#

oh nicky i just got what you say yeah he can use sessionStorage

opaque rivet
#

No, store it in cookies. Not localstorage or session storage. These are only accessible by the clientside, but the server may want to change these cookies with a Set-Cookie header.

nimble epoch
#

oh yeah you mean django cookies for example?

opaque rivet
#

I literally mean cookies.

nimble epoch
#

of course

inland oak
#

I have a div container, which contains bootstrap table

#

I wish to receive result....

#

is it possible somehow to make them diving screen in three parts?

#

Table main has hundreds of rows
Table 3 has small amount of content to fill itself fully
Table 2 has content to fill twice of its size

#

looking for some tutorial for that

nimble epoch
#

why dont you use grids?

inland oak
#

well, it is the answer I was looking for

#

googled

opaque rivet
#

Grid or flexbox

inland oak
#

Thanks

nimble epoch
#

then use table in eachone

inland oak
#

greed is good

nimble epoch
#

i mean if you want to have that table shape you can use table inside

inland oak
#

I'll need to clarify end result

#

a moment

#

green shows three vertical scroolbars

#

which I would need for each table

#

grid should probably suit my case, right?

grizzled trellis
#

I have just completed Django
Made a Portfolio Page, Blog App, Polling App, Forms.
Can you guys suggest me what project should i do next?
I want to do a Big project that can be added in my resume

nimble epoch
#

yeah

inland oak
#

great

#

thanks

#

good to know the direction of my road

nimble epoch
#

yw yeahhh

nimble epoch
#

am i right?

#

like Follow system, Like, Comment

grizzled trellis
#

You mean a social media app?

nimble epoch
#

of course

#

and that eazy

grizzled trellis
#

Okay i will try it

#

Thank you

nimble epoch
#

yeah yw

opaque rivet
#

If I want to port my current django app to docker, I use a redis installation on linux.

As well as installing python dependencies, am I able to install redis with apt?

nimble epoch
opaque rivet
#

Will my redis / postgres DBs be in a different docker container to my django container?

calm plume
#

They can be in the same one

inland oak
calm plume
#

For example, PyDis site has both the Django site and the postgres db in the same container

opaque rivet
#

Ah okay. If I have django and postgres in seperate dbs, I'm a bit confused on how they can communicate - since they're in different VMs essentially?

inland oak
#

I have somewhere example of docker compose scenario

#

which has Django, Regis, Postgres in different containers

opaque rivet
#

@inland oak so you have 4 different docker files?

#

3*

inland oak
#
version: '3'

services: 
    django:
        build: .
        container_name: django_service
        command: >
            bash -c "python manage.py makemigrations
            && python manage.py migrate
            && python manage.py runserver 0.0.0.0:8000"
        volumes: 
            - .:/app/
        ports:
            - 8000:8000
        environment: 
            - DEBUG=1
            - DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1
            - CELERY_BROKER=redis://redis:6379/0
            - CELERY_BACKEND=redis://redis:6379/0
        depends_on: 
            - redis
    celery-worker:
        build: .
        container_name: celery_worker
        command: celery -A fampay_youtube worker -l INFO
        volumes: 
            - .:/app/
        environment: 
            - DEBUG=1
            - DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1
            - CELERY_BROKER=redis://redis:6379/0
            - CELERY_BACKEND=redis://redis:6379/0
        depends_on: 
            - django
            - redis
    celery-beat:
        build: .
        container_name: celery_beat
        command: celery -A fampay_youtube beat -l INFO
        volumes: 
            - .:/app/
        environment: 
            - DEBUG=1
            - DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1
            - CELERY_BROKER=redis://redis:6379/0
            - CELERY_BACKEND=redis://redis:6379/0
        depends_on: 
            - django
            - celery-worker
            - redis
    redis:
        image: "redis:alpine"
#

it is not mine, but I hope one day to use it

#

perhaps it can be useful for you too

#

mm yeah, it is Django, and Celery/Redis actually compose scenario

inland oak
#

each section has build, which I suppose makes another container

#

and each section is launches different container as far as I can read

opaque rivet
#

Oh so, a docker file is a docker image? And within that image you can have different containers?

inland oak
calm plume
#

A Dockerfile is a "recipe" for building Docker images

opaque rivet
#

Alright, I'll watch some guides on it to understand it better

inland oak
#

because it wraps your application with specific OS inside of the container

#

helps for easy installing to multiple machines with different OSes

calm plume
#

A language agnostic one

opaque rivet
#

@calm plume do you know how I'd use docker in a ci/cd pipeline? Would I be creating a new container on each deploy?

calm plume
#

I haven't done it myself, but I think you would generate a new container from the image

#

Or maybe you could use docker-compose

oblique stump
#

which yt channel and website would be perfect to learn django? any suggestions? I am new here and I'm looking forward to learn web development

calm plume
#

The official Django tutorial is amazing. And I think Corey Schafer has a video series on Django.

winter pivot
#

Hello im using django rest framework and react. I have an Authorization and application/json in the react headers but it returns a 403 unauthorized when connecting to server . Why is this? when i test it in postman, it works

inland oak
#

I tried making grid

#

but it is not limiting my screen

terse vapor
#

its pretty good on my screen

inland oak
#

click Commodity or Ship

#

Tables are much bigger than grid is defined

calm plume
#

Looks like this to me

winter pivot
#

anyone here knows react with drf?

calm plume
#

Oh the tables

inland oak
#

it is too big%

#

I hoped to limit it to grid

calm plume
#

You can stick grid inside a container

#

That's a certain width

inland oak
#

I'll probably rethink what I do with loading speed though

terse vapor
terse vapor
inland oak
#

eh, something got just broken)

#

all right, trying to limit size of container containing grid then

oblique stump
#

Has anyone watched django tutorial of yt channel called Clever Programmer?

#

if you have what would you rate on the scale of 10?

inland oak
#

I do something wrong probably with table?

calm plume
#

Stick a container around the table then

inland oak
#

is it possible to fit the table into grid, and for table having its own scroolbar inside?

calm plume
#

Or nest the table inside the grid

inland oak
#
<div class="grid-container">
    <div class="item1">

        <p id="main">This is Main Table</p>
    </div>
    <div class="item2">
    </div>
    <div class="item3">
        <p id="secondary">This is Second Table</p>
        Footer
    </div>
</div>
#

I already stick grid around table%

calm plume
#

That <div> looks off

inland oak
#

the table is <p id="main"></p>

calm plume
#

The top one

inland oak
#

well, it was just bad copy

#
.item1 {
    grid-area: main;
}

.item2 {
    grid-area: right;
}

.item3 {
    grid-area: footer;
}

.grid-container {
    display: grid;
    grid-template-areas:
        'main main main main right right'
        'main main main main right right'
        'footer footer footer footer footer footer';
    grid-gap: 10px;
    background-color: #2196F3;
    padding: 10px;
}

.grid-container>div {
    background-color: rgba(255, 255, 255, 0.8);
    text-align: center;
    padding: 20px 0;
    font-size: 30px;
}
#

I'll try to start with stripping table from its style, perhaps they are the issue

inland oak
#

hmm, may be somewhere I could find working example

opaque rivet
# inland oak ```css .item1 { grid-area: main; } .item2 { grid-area: right; } .item3...

hmm, you didn't specify any grid-template-rows or grid-template-columns. In my opinion, I think it's much easier to use flexbox:

<div className="flexbox-column">
  <div className="flexbox-row">
    <!-- These two items are next to eachother. Specify their relative widths. -->
    <div className="item-1"></div>
    <div className="item-2"></div>
  </div>
  <!-- This item is below item 1 and two and takes 100% width -->
  <div className="item-3"></div>
</div>
.flexbox-column{
  display: flex;
  flex-direction: column;
}

.flexbox-row{
  display: flex;
  flex-direction: row;
  align-items: center;
}

also I just realized i wrote JSX not HTML. That's reacts toll on me...

#

also you can give your item divs a fixed height, and have overflow-y: scroll to be able to scroll through the table.

inland oak
#

how to specify relative widths of first two items just to be sure? 😉

opaque rivet
#

so for item-1, you can say width: 80% for example

inland oak
#

ah got it

#

not yet at the finish

#

but getting closer

#

it works exactly like I wish

#

❤️

opaque rivet
#

nice, FYI your item-2 has to have a width of 20 or lower to be on the same row.
if you want to jazz it up a bit:

.flexbox-row{
  display: flex;
  flex: 1;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}```

`align-items: center` will vertically center both divs in the row. `justify-content: between` will place both divs at opposite ends of the row. `flex: 1` should mean that both divs have the same proportion of the width of the row (if my memory is right).
prisma nebula
#

Well, I am trying to link a CSS file to an HTML file. But it's not working ( Can anyone can help me with this )

foggy bramble
#

I'm using django-authemail for login, signup, logout, password_reset, and password_change.
I want to override email message, anyone knows how to do that?

opaque rivet
inland oak
prisma nebula
opaque rivet
inland oak
#

between is not acceptable argument

#

perhaps space-between?

opaque rivet
#

yes sorry, space-between.

inland oak
#

well, it did not work

opaque rivet
#

hmm 🤔

nimble epoch
#

@inland oak you couldve just used bootstrap row class

inland oak
#

i am almost close

#

I feel it

#

those flex boxes are exactly working like I wished

#

I have scroll bars as I desired

nimble epoch
#

of course they do

inland oak
#

style for flexbox-row did not reach itself

opaque rivet
inland oak
#

🎉

lament glade
#

Anyone here use jinja2 much?

nimble epoch
#

i used to its similar to django template. you need help?

lament glade
#

Yeah, just had a quick question about looping over an include

dusk portal
dusk portal
lament glade
#

So I'm looping over a list of dicts:

{% for post in posts-%}
    {% include 'post.html' %}
{% endfor %}

And I want the included template to render each one using the data in the dict. How do I set "post" as the top level context for each time it loops include?

hot crest
#

Hi guys, I have a really important question.
I want to build a website, like stack overflow but with much much fewer features:
==> users are able to post a question or answer another existing question

The only difference that I want it to be real-time/live whatever you call it

I want to use WebSockets so whenever someone posts a new question you can see it in real-time and neither when someone answers a question

however, I have no idea how to deal with these data and store them in the database

Could someone explain to me, please?

should I store the data that comes through WebSocket in the database!?
🙄

nimble epoch
dusk portal
#

u can fetch data from database by jinja not whole template

#

lol

inland oak
#

perhaps you are looking for this?

dusk portal
#

u use flask or django @hot crest

hot crest
dusk portal
hot crest
#

Yea I know that I need to use Django but
I dont
Can you explain more in details?

lament glade
nimble epoch
#

@lament glade you want to iterate through each post then show then one by one in your page, right?

inland oak
#

ah, I think I got what he wishs

#

it can be done

terse vapor
opaque rivet
inland oak
#

you are essentially trying to do something like that

#

you can pre render your posts with different jinja template, before submitting already rendered to new render template

hot crest
#

@opaque rivet Yes seems like It needs a bit of time to learn
I already know Django and working with DRF mostly
But after all, lets say i made a connection between users with channels,
is that okay to store the datas in a sql database like psql?