#web-development

2 messages · Page 122 of 1

hybrid bobcat
#

yea if you wanna get into that, you can try CodeForces

gray stone
#

Yes i hate this shit

gray stone
hybrid bobcat
#

the minimal amount of knowledge you need to do that is at least some knowledge in alg2

hybrid bobcat
gray stone
#

i dont have that much time to focus on such a thing

#

i already have school

#

anyways im into web-dev but for now its just front-end

hybrid bobcat
#

determination = possible success , non determination = nothing

native tide
#

you should do algorithms and problem-solving, that's for sure. advent of code is running, that's a good place to start.

hybrid bobcat
native tide
#

not linked to this discord, but it's a coding event

native tide
#

there's an advent-of-code channel in this discord discussing solutions too

gray stone
native tide
#

plus it covers things which you probably won't come across often, such as regex, so it's a good way to learn something new

gray stone
#

front end is much funiear man

#

i think back end is like a nightmare for me lol

hybrid bobcat
#

bruh

#

backend is easier

#

frontend is nightmare

#

you have to format those stupid css stuff

gray stone
#

u mean python sql and these shit r funny ?

hybrid bobcat
#

they're fun not funny

gray stone
#

u better step the fuck up man '

native tide
#

this is feeling off-topic

gray stone
native tide
#

doing frontend becomes more enjoyable with frameworks like angular/react

#

they have nice libs (e.g. for animation)

gray stone
#

tell him, Nut

native tide
#

what are you on about

gray stone
#

uhmmm

#

i was tryna to ask if its worth to learn some web dev shit?

native tide
#

I am following along in the Django for Professionals book and I am stuck at the first chapter where you create a django project and app
using pipenv and then Dockerizing it
when running docker build . I get the following error
=> ERROR [4/5] RUN pip install pipenv && pipenv install --system
I ignored that, made a docker-compose.yml file
and ran docker-compose build
and got this error
ERROR: Service 'web' failed to build : The command '/bin/sh -c pip install pipenv && pipenv install --system' returned a non-zero code: 2
This is my Dockerfile:

FROM python:3.8

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /code

COPY Pipfile Pipfile.lock /code/
RUN pip install pipenv && pipenv install --system

COPY . /code/```
This is my `docker-compose.yml` file:
```docker
version: '3.8'

services:
  web:
    build: .
    command: python /code/manage.py runserver 0.0.0.0:8000
    volumes:
    - .:/code
    ports:
    - 8000:8000```
quick cargo
#

Low key

#

Would never use pipfile

#

With or without docker

#

But even more so with docker

strong vault
#

is anyone good with flask and jinga? would really appreciate some advice on a project thanks

#

its a super simple project. nothing complicated :D

half otter
#

Anyone want a site made for them? I'm doing this for hours and not money. I need volunteering hours

thick kayak
#

hi guys:) anyone could give me advice on where to learn django

tribal badger
#

Hey who does web dev for shopify here

nova sparrow
real lynx
#

Is it possible to call a function of a loaded JavaScript file from a Flask app?

I was thinking of creating an endpoint that the JS file constantly queries and that tells it what to do. But is there a more efficient way?

wild echo
#

Can I mix 2 flask apps

wild echo
real lynx
#

I want to modify DOM elements at certain times from the backend
I have functions in a JS file to do that
Is it possible to call those functions from the backend?

weary hatch
#

hey, i had an important HTML related question? can anyone help me with that?

gaunt marlin
weary hatch
#

good idea, um

wild echo
#

HTML comes under #web-development i guess, which means you can skip straight to your question 😉

weary hatch
#

i have this quiz kind of thing that i have to solve, and i know one can get the correct answers through inspect element. it depends on whether the website is static or dynamic

#

but i'm not an expert in that field, so i wanted someone who can help me with that to tell me quickly if it's possible to get the correct answer of an mcq question on this specific website or not

wild echo
#

lmaooooooo you want us to help you cheat

#

nice

weary hatch
#

figure out if it's cheatable or not, yes hahah

#

well not really

#

it's complicated

wild echo
#

which website

weary hatch
#

can i screenshare?

wild echo
#

nah jus share link

weary hatch
#

it's a private organization

wild echo
#

not a problem

weary hatch
#

don't think you can access

wild echo
#

just share ffs

#

not about accessing

#

i can just check it up

weary hatch
#

sure

#

does this work?

wild echo
#

wait up

weary hatch
#

aight

wild echo
#

PM

wild echo
weary hatch
#

?paste

wild echo
#

what

#

I would like to mix 2 flask apps, I was thinking of using subdomains but can't because the host I use pythonanywhere.com does not support subdomains in flask

vestal hound
real lynx
#

Thanks 😄

sinful pulsar
#

anyone could help how to handle files in this curl?

curl --request POST --data-binary '@/home/test.bin' http://xxx/api/SubmitWebLog/

i'm using django btw

#

using .read() gave me error

wild echo
#

you wanna curl in python?

#

you don't request.body.read()

wild echo
wild echo
opal haven
#

I believe not

echo mesa
#

Can you help me with that?

#

I get an error

#

NoneType object has no attribute 'text'

violet pond
#

@echo mesa can you show me the relate code and what object you are attempting to get the text attribute off of?

echo mesa
#

I already solved this but thanks ! I have another problem

#

Can someone help me with Flask, Jinja2?
I'm trying to set the onchange of a field created using FieldList to run a function with giving the parameters of it's id
Essentially making a table of SelectField which after each one changes it will trigger a JS function which adds it's it's id to a Hidden field that on POST I will get and update the corresponding things in my DataBase

primal kernel
#

Hey there! quick question!
I'm developing a DJANGO APP and there are some actions that have to be done one time every month. I need to save the last time they were executed and show it in the app.

My question is: how should I save that date? Should I write it in a file, should I create a model for it?

Thank you !!

native tide
#

can someone help me with starting Django

#

well coffee first

clear arch
#

Not Found: /styles/navbar_styles.css
why does it add / before the styles?

#

<link rel="stylesheet" href="styles/navbar_styles.css">

wanton gyro
#

Hello, this question is regarding development
how to delete all the browsing session information such as history, cache, cookies, downloads, saved passwords, etc for an stateless webservice that allows one to interact with two web-browsers: Google Chrome and Mozilla Firefox such that the service should support endpoints /cleanup with a browser parameter which can any like chrome or mozilla?

for ex. http://<server>/cleanup?browser=<browser>
should clean up the browsing session for the given browser if has been stopped.

faint pelican
clear arch
faint pelican
# native tide okay

Sorryy hehe. I just started learning Django yesterdayy, tried watching videos etc but im quite slow. Try some mini project like the polls/todo app and I think i get the concept of django bit by bit

clear arch
#

nvm I just changed some settings

faint pelican
#

Hello Arnav

#

I think

#

Oh its working now

#

?

clear arch
#

yes

faint pelican
#

What did you change?

clear arch
#

well the path to STATICFILES_DIR was set wrong

faint pelican
#

I seee that is one of the way too

#

What i did yesterday was using something like this:
<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}">

#

This is my files

clear arch
#

yep and I also forgot to {% load static %}

quaint spade
#

So I have a list of items(rows) that a user can purchase, and it adds to the total price correctly when they add a new item, but when a user deletes one of the items, the price doesn't drop/update

function ListFieldRowCount( listField, totalField ) {
    var totalRows = jQuery( listField ).find('table.gfieldlist tbody tr').length;
    jQuery( totalField ).val( totalRows ).change();
}
function ListFieldRowTotal( formId, fieldId, totalFieldId ) {
    var listField = '#field' + formId + '' + fieldId;
    var totalField = '#input' + formId + '_' + totalFieldId;
    ListFieldRowCount( listField, totalField );
    jQuery( listField ).on( 'click', '.add_list_item', function() {
        ListFieldRowCount( listField, totalField );
        jQuery( listField + ' .delete_list_item' ).removeProp( 'onclick' );
    });
    jQuery( listField ).on( 'click', '.delete_list_item', function() {
        gformDeleteListItem( this, 0 );
        ListFieldRowCount( listField, totalField );
    });
}
ListFieldRowTotal( 158, 1, 7 );
//ListFieldColumnTotal( form id, list field id, result - field id );
// enable dynamic population on field that is to hold result
</script>```
#

any ideas?

opal viper
opal viper
hollow scaffold
#

Hey guys! I'm looking for a solution in Django to live enable/disable models or views that doesn't require me to perform an 'if' check in the templates

#

Like enable_blog=False, hide it from admin and disable the view

slow shale
#
if BLOG_ENABLED:
  class Blog(ParentSomething):
    ... awesome code ...

Perhaps? Not sure about Django.

hollow scaffold
#

@slow shale tried that the main issue is that the server has all the source code cached in the background

#

which means I'd have to reboot the server for it to take effect

#

found a workaround for disabling the view while Live, but doesn't remove it from the admin menu 😦

slow shale
#

Ohhh. You basically want Django to restart the webserver with different values.

hollow scaffold
#

I might have to

slow shale
#

Hmm. They may have "hot" reloading but that's usually reserved for development due to possible performance implications I think.

hollow scaffold
#

pretty much my thoughts

#

I guess I'll dig into the admin html template and see if there's a simple way to modify it

#
{% if module.enabled %}
<a.....>
{% endif %}
#

Figured it out

#
# blog.admin
def blogAdmin(model.Admin)
    model = Blog
    def has_module_permission(self, request):
        if checkModuleEnabled():
            return True
        else:
            return False
haughty turtle
#

@native tide when you use React with Django do you just use the standard NPM package with create-react-app?

#

I was reading a guide on how to use Django and React together and it seems to be just two servers running seperately, so React is rendering its own pages, while it grabs all that is needed by fetching it from the server.

#

So when using React really will I not be rendering anymore with Django just with React?

#

I see myself just using Django to return a JSONResponce and using that on any renders for any use of items in backend is this correct?

native tide
#

Yes use CRA. (create-react-app). You'll essentially have your front-end separate to your backend, with the React making API calls to your views.

Having your frontend and backend seperate means that you will have to use webpack (which CRA has scripts for) to bundle your static files. Then, Django can render your index.html of your React app and the rest is handled by the frontend. (this is done by just changing the STATICFILES_DIRS

However, you can also stick with templating and just sprinkle some React in there from the staticfiles in your Django project, that way, things are simpler and the frontend and backend are not "seperate". This would be server-side rendering while the other one would be client-side.

^ I've never tried this method but it'd be cool to know how to explicitly. Here's a cool article which helps:

https://mattsegal.dev/django-react.html

@haughty turtle

Matt Segal Dev

An opinionated guide on adding React to a Django project

haughty turtle
#

Thanks @native tide looking into it

native tide
#

That blog kinda goes through all the webpack stuff which is already included in CRA, so this is how you actually get the react / django to co-exist on the same server:
https://blog.usejournal.com/serving-react-and-django-together-2089645046e4

Django will just render one page and the rest of the routing is done client-side

Medium

Reactjs is a nice framework for frontend and Django REST framework (DRF) is another great framework for API development. I wonder how to…

halcyon dragon
#

Pls help

#

@desert sand @hollow scaffold @haughty turtle @native tide

native tide
#

@halcyon dragon what are you hoping to see when you run django-admin? Try django-admin-help to see available commands.

haughty turtle
#

django-admin startproject mysite @halcyon dragon

#

@native tide I mean I actually think rendering from React will be better as it prevents double the work from being done.

native tide
#

Yep there's pros and cons to server-side and client-side rendering

#

on server-side there's better SEO and indexing by search engines

#

but client-side is faster

quick cargo
#

Well...

#

It's slower for the user, less load on the server

native tide
#

slower for the user?

#

with React, since you're just mutating the virtual DOM, wouldn't it arguably be faster for the user since they don't have to wait for the server's response?

quick cargo
#

They still have to wait for the server to respond

#
  • the js rendering time
#
  • the sub requests that still get sent
#
  • the extra processing time required to route and load elements to be rendered
#

Jinja and Django both take less than 0.1ms to render your average page

#

And that's with alot of templating with inheritance and all that

#

Slimmer pages can easily go into the micros

native tide
#

well for the first render, sure, iirc with React apps the whole application is rendered at the first request, right? But then you save time due to not having to refresh the page and the virtual DOM mutations etc

quick cargo
#

Sure you have that once it's loaded its mostly done

#

But you still have that biggg load time at the start

#

Plus things like images etc...

#

Client side rendering is pretty much always more of an advantage to the server not the client

#

If the server is any sort of reasonable and consistent latency

native tide
#

then again there are methods to split the JS downloads so you don't download the whole application at once (not that it's really a problem for the most part) but I haven't had experience with it

#

I think web-apps should all have some JS in there of some sorts

#

it adds so much more.

haughty turtle
#

How do companies do it @quick cargo ?

quick cargo
#

I think js is over used tbh

#

In places where it would be better without

native tide
#

@haughty turtle I heard that a general rule is to not worry about performance until it's actually a problem

quick cargo
#

From a servers perspective client side is great

#

Cuz suddly you cna just have one large static content server

#

Cache everything

#

Low load, high output per worker

native tide
#

talking about servers & backend, I'm really stuck between choosing express.js and django

#

@haughty turtle also if you're doing react and you want some really cool animations

#

I've heard Framer Motion is good

#

I've also used react-spring but the docs are not as good as I hope for more complex animations, but for simple ones it's awesome

quick cargo
#

Litterally no competition

native tide
#

you know what's really confusing though

#

on a lot of jobs (referring to fullstack, etc.) employers want node.js. it's so confusing because what is that referring to? express.js?

then you go and search for express.js jobs explicitly and it's less than that of django

quick cargo
#

Node.js has its own HTTP framework iirc

#

Express is shit though

#

Slow, unreliable and inconsistent

native tide
#

so, node.js is a backend in and of itself?

#

I thought it was something that encapsulates lots of other things, like an umbrella term

quick cargo
#

It can be yes

#

It's significantly faster than express

#

Similar system as with go lang's inbuilt HTTP ext

native tide
#

hmm, so in that case it would be worth learning node.js?

quick cargo
#

Meh

#

It wouldn't hurt to get comfortable with js cuz front end

#

But backend wise I'm not personally massive on it

native tide
#

i'm pretty comfortable with js, it's just that I'm so confused when job listings want 'node.js'

quick cargo
#

Most will use it as a umbrella term

#

Cuz recruitment agency's just slap as many buzz words on as possible to get higher listings

native tide
#

yeah that's true

#

so I guess when they use node.js they are referring to npm libraries like react

#

or just js in general

haughty turtle
#

Prob to npm libraries

wintry imp
#

hi

#

hola

uncut harbor
#

is there anyway to both set and get to/from local storage using flask?

hybrid bobcat
#

anyone know how i can have subdomains share the same app instance with the base domain in Flask?
I have a view function that redirects to a subdomain, so like sub.base:5000 (yes i am running locally), but apparently this will not work since subdomain is not a thing for localhost, I heard I can have a thing called matching_subdomain set the true to have Flask to match against. I also specified the base domain by using app.config['SERVER_NAME'] = "base:5000" and also a hosts file on my computer (I'm in virtual environment so not really sure how that'd work).
So anyways, I've got those done, and I nevigated to the subdomain which works fine and it returns and renders a html template as I have set it to in the views. The problem is, the app.teardown_appcontext thing is called after I nevigate from the base to the sub, which makes sense to me, does anyone know how to have the subdomain and the base domain (running as localhost btw) to share the same app instance so app.teardown_appcontext doesn't get called?

#Flask #Python #WebDev

past cipher
#

anyone know if there is a Discord dedicated to Flask

#

all's I mostly see in here is people firing questions and getting no answers 🤣

vestal hound
#

as opposed to React, Angular, Vue, etc., which use JS as a frontend language (running in the context of the browser)

wheat cove
#

Hey can anyone help me in using notebook script for website

marsh canyon
#

can you share the script

#

and what actually is the issue

wheat cove
#

I've made a speech to text code from scratch in colab

#

Now I want it to be hosted onto the web

#

How do I host the script and all the required libraries on the firebase

thin dome
#

hello ?

#

how to solve multi value dict error in django?

#

???

native tide
#

hello

shy hound
prime parrot
#
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 936, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1017, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1002, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 916, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 485, in sock_connect
    return await fut
  File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 517, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 2333)```

My Lavalink Bot cant start. This is executed on a Ubuntu based v-server
steady trout
#

Does anyone know a good tutorial for setting up a Virtual Enviorment in VS code for a django project/ django tutorial?

gusty hedge
golden pollen
#

anyone who knows how to fix the "Getting default adapter failed" tried on google, loats have had it, can seem to fix it tho

#

im simply opening a website, literally nothing else, and it crashes down after 2 seconds (selenium)

gleaming basin
#

ok

vernal furnace
#

put python before django

#

python django-admin startproject music_controller

#

@gleaming basin

gleaming basin
fallen spoke
#

I am using libmagic to check the MIME type of a file on user upload but I have 2 questions: 1. Do I need to check the file extension too? 2. as far as i know, even seemingly harmless files can be malicious (for example, mp4 can be malicious) how do I verify that the user uploaded file is not malicious? (I am using django)

haughty turtle
#

Scan it with a anti-virus on your server? @fallen spoke

#

Or send the file to virustotal.com through selenium and obtain the response ?

fallen spoke
haughty turtle
#

If their ToS permits, don't see why it wouldn't allow you to.

fallen spoke
haughty turtle
#

They allow 500 request per day on the Free API and unlimited on Premium API

#

Up to you if you think you surpass the 500 request per day limit @fallen spoke

#

As far as local scanner I like Malwarebytes, up to you which route you follow.

fallen spoke
#

Thank you so much, I appreciate it

haughty turtle
#

Scanning your file locally is going to use up Resources, so your going to have to likely upgrade at some point your local server.

fallen spoke
fallen spoke
remote ruin
#

hey guys, how do i make my webpage properly react to zoom?
right now i have this problem

#

the background img doesnt change at all, but all the other stuff

haughty turtle
#

@fallen spoke the paid version of Malwarebytes offers CLI Scanning, try looking for a anti-virus that offers CLI Scanning for free, if not look at automating this yourself.

timber dune
#

hi,

#
    def get(self, request, format=None, **kwargs):
        quiz = Quizzer.objects.get(slug__iexact=kwargs['slug']) # case insensitive LIKE clause
        questions = Questions.objects.filter(quizz=quiz)
        answers = Answer.objects.filter(question=questions)  # need help here
  
        serializer = QuizzSerializer(questions)
        return Response(serializer.data)```
#

how do i get all the(list of) answers object for the questions(list of objects)?

#

I want a serializer which will return all the questions and thier options for q quiz

near bison
#

Can you point me to a good resource about django async form validation. (no reload). ?
and , How do i verify a phone number by sending an SMS to it. ? any api's to achieve this ?

#

How to leverage django rest framework to achieve the form validation?

#

While still being able to get the csrf protection

haughty turtle
#

You can use FETCH, send a request to you server where it sends a SMS and in your page you await for a reply with the code sent all this without reloading.

#

@near bison

near bison
#

This is just the basic idea. i was talking about how to acheive this with rest framework and how to validate on the go. (before submit)

haughty turtle
#

@native tide yeah React is different from Vanilla JS, thought the difference would not be so huge but I can see why it would be hard to understand Vanilla JS starting from React

#

Ah I don't use the REST framework, and validate the code on the go would be done with JS on change state of the input field? @near bison I mean I would simply achieve all of this with JS and FETCH

near bison
#

Thanks 😄

#

@haughty turtle Is it necessary to render the form as a django form object ? Does this method prevent csrf atttacks ?

native tide
#

@near bison Are you using JS? If so, you can do form validation on the client-side and that would be easier & faster than having to wait for the server's response.

near bison
#

Yes. vuejs

native tide
#

@haughty turtle So with vanilla js were you using node.js?

#

@near bison So you could just render your form through vue.js and validate your inputs. If you need your Django backend to validate any inputs, such as whether a username / email exists, you could make an API endpoint with rest_framework and make requests to that endpoint from your frontend as soon as your form is submitted.

I recommend using the axios library over fetch, it has some advantages over it.

#

Also what do you mean by this:

"Can you point me to a good resource about django async form validation. (no reload). ?"

Meaning that when you submit the form, you want to page to not refresh right?

lean moss
#

If I'm going to start a django project that will eventually be deployed somewhere, is it fine if I start using a private github repo with the default security settings? Or should I clean those up before I even start a repo?

haughty turtle
#

@near bison Via JS you add a CSRF token directly into your request

proven dune
spiral smelt
#

input always return a string, so when you type 1, the eleccion variable is actually '1'

#

Either wrap the input() in an int() (int(input('blah'))), or compare eleccion with '1' (if eleccion == '1':)

proven dune
#

Thanks, I realized a second later 😅

fleet heart
#
list = [1, 1, 2, 3, 5, 8, 13]
print(list[list[4]])

list2 = [1, 1, 1, 2, 3, 5, 8, 13]
print(list2[list2[4]])

#

Hey guy

#

why the list 1 show me 8, i thought it was 5 and the list2 show me 2 but i thought it was 3, like we count from 0

haughty turtle
#

@fleet heart You are accessing your index wrong

#

list = [1, 1, 2, 3, 5, 8, 13]
print(list[list[4]])

Here you are getting list[4] which is 5 then using that to get list[5] which is 8

#

It's like doing

list = [1, 1, 2, 3, 5, 8, 13]
x = list[4]
print(list[x])```
#

You are doing the same for list 2

list2 = [1, 1, 1, 2, 3, 5, 8, 13]
x = list2[4]
print(list2[x])```
tacit flare
#

btw is it recommended to name a variable with the name of a class?

haughty turtle
#

NO

tacit flare
#

I mean is list an appropriate name for a variable?

haughty turtle
#

list is built into Python, not recommended at all. @tacit flare

tacit flare
#

Thanks!

fallen spoke
#

How to make django use normal user db for for superusers instead of auth_user?

vernal furnace
#

wait why django is not enough for web development, why I have to use javascript? the tutor said so but everything I did was possible in django?

stray cloud
#

because websites are powered by js and JS opens new ways to interact with the DOM and more

manic frost
stray cloud
#

At the core, you need javascript for web development

vernal furnace
#

@manic frost Isn't that what django do?

manic frost
#

Browsers can only execute JavaScript.

vernal furnace
#

@stray cloud What is DOM 👀

#

Ohh

#

Now I kind of get it

manic frost
#

The only way you can update the data on a page without JS is to reload it and simply get new HTML from the server

stray cloud
#

from javascript

vernal furnace
#

I saw a video on youtube where he updates the status of online/offline users without reloading the page

#

so basically the only way to do that is with javascript?

manic frost
#

yes

vernal furnace
#

nicee

manic frost
stray cloud
manic frost
#

No, the term is correct

#

🙂

vernal furnace
#

Wait so should I still use django ?

stray cloud
manic frost
vernal furnace
#

Can you link me to a tutorial where someone uses Javascript and Django together

stray cloud
vernal furnace
#

Javascript is kind of easy I saw it once, hope I can get used to it fast

stray cloud
#

You understand?

#

They always go togheter, but they do different things.

vernal furnace
#

Yes

#

Nicee

stray cloud
# vernal furnace Yes

Also, pesonal note that I haven't done and I feel sorry for it. Learn TypeScript while/immediatly after learning JavaScript.

#

It will make it much easier for you in the future.

#

It's just like C++ for C, TypeScript just adds more features.

vernal furnace
#

oh

stray cloud
#

So, what you learn in Js applies to TypeScript anyway

vernal furnace
#

Thanks btw, Imma spend this whole week to learn javascript

stray cloud
vernal furnace
#

Btw, the base javascript right?

#

Like no react.js or stuff like that

stray cloud
#

React, Vue, Angular they are just frameworks you have to know JS beforehand

#

But as I mentioned, most of them work better with TypeScript (especially Angular)

vernal furnace
#

Thank you so much

#

To both of you

stray cloud
glass badger
#

Semi-off topic, but whats the best way to install node js for a django app running on ubuntu?

verbal snow
#

I keep getting AttributeError: 'User' object has no attribute 'pk' when trying to use django admin site

fallen spoke
#

How do I store something like a token on client side like a token? cookies? local storage? something else? and how do I do it on django ( I want something that works both on mobile apps and on browsers). this might be a stupid question but I have never used any of these before so bear with me please

verbal snow
#

What ID?

#

I literally go to the admin site and it errors

#

It started out of no where

versed python
#

How can I share a website over local wifi? For example I run a django server on my laptop using pythgon manage.py runserver. How can I see that website on my mobile (connected to the same wifi)? I think this can be done using ngrok but I want a simpler solution.

gaunt marlin
#

@versed python get the local ip of your pc that hosting django , add it to ALLOWED_HOST in settings, run the server with python manage.py runserver 0.0.0.0:8000 to expose port 8000, after that you can access it from your phone in the same wifi network with "your local ip":8000

versed python
#

Yeah I just figured it out

#

How can I find the local ip though?

gaunt marlin
#

type ifconfig in your console

versed python
#

I found mine using npm which shows it if i change the default host

gaunt marlin
#

your local ip will start with 192.168

versed python
#

however django doesnt

versed python
gaunt marlin
#

did you ran django with python manage.py runserver 0.0.0.0:8000?

versed python
#

I am working on an npm project. I just gave django as an example

gaunt marlin
#

@versed python then you need to find out how to expose port with npm

versed python
#

Actually you already solved it

#

I found my ip using the command and tghen changed the npm host

#

Thanks!

gaunt marlin
#

you are welcome

granite pasture
#

does this channel also include whatsapp bot development?

smoky terrace
#

Django question => Lets say i want to render the same thing on all pages, I use a layout template

How do I now pass in some variables which are needed on every page.

This could be done when **rendering **something in the **view ** with the use of the CONTEXT parameter of the render function but that would be repetitive. Is there any other way to do this without repeating myself?

marsh canyon
#

you can make your own base View class where the context value is predefined

#

like how the generic views do it

smoky terrace
#

thanks

marsh canyon
#

wait, lemme get the docs

#

this

#

do look up some examples online

#

with a simple google search

#

Now I am curious to see how generic views handle their context 🤔

#

I think another way is have a base view which inherits ContextMixin and define your own get_context_data method with some defaults in place

#

I have not tried it tho

#

but worth trying out

#

just like how they set kwargs.setdefault('view', self), you can do that for your values

#

a little more setup is required

#

I will try this method later and let you know

#

or just have a method like this

def get_context(**kwargs):
    return {
        "name": "someone",
        **kwargs
    }
``` and invoke it while rendering the template @smoky terrace
#

return render(request, template_name, get_context(some_info="idk", age=20)

sinful helm
#

web dev using python? 😂

#

that sounds horrible, my friend did it once and basically balled his eyes out and got nowhere

chrome coral
#

Would that be a good idea to make a website by using Django and using js in it? Or simply start with js?

slim beacon
#

Hey all,

I was hoping someone can point me in the right direction.

Basically I wrote a text based game in Python that asks for input from the player and prints to screen various text as part of the game.

Essentially like this:

What will you do?

walk

Player walks

What I'm trying to do is have people be able to play the game on my site. So essentially, on a page have a part where the user can input text and then the games prints to an area on the screen and this continues until the game is over.

I was looking into AJAX requests, and even having a Python IDE be rendered on the site as to run the code using Skulpt, but I'm still at a loss on how to implement this.

Can anyone point me in the right direction?

cerulean zealot
#

is there a way to extract all the clickable points

#

of a site knowing almost nothing of html

#

clickable points means get you to another link

#

already get

twilit needle
#

can someone pls help me with drf here?

#

thanks!

open owl
cerulean zealot
#

im failed at both

open owl
twilit needle
#

pls ping me when help, thanks!

cerulean zealot
#

what specifically?

#

its too much output in a format that I don't know

open owl
sly echo
#

Hello

#

Anyone?

cerulean zealot
#
url_input = ('url:')
r = requests.get(url_input) 
print(r) 
print(r.content) # The output is too long
#

well let me format the code, I thought nobody would take it seriously

analog arch
cerulean zealot
#

button elements

analog arch
#

I believe you'll have to first understand how the buttons are implemented on the given site, but if they are just <a> tags with a btn class then it should look something like this.

`from bs4 import BeautifulSoup

body = requests.get(url_input).text
soup = BeautifulSoup(body, 'html.parser')
links = [a['href'] for a in soup.find_all('a', {'class': 'btn', 'href': True})]`

vestal hound
twilit needle
#

The issue is now closed

#

This really helped me a lot, thanks! I think its worthwhile to check, too, regarding drf serializers circular import errors

gaunt marlin
#

i would use the websocket method if it's a game

slim beacon
#

@o0o0keem#9279

Thank you. I did take a look at jQuery but hit a roadblock. I'm going to look more into websockets!

strong umbra
#

Can i run js in console ???

native tide
#

@sinful helm yep web dev with python. It's extremely popular.

#

@strong umbra in the browser console? Yes

strong umbra
#

Ok . But in cmd or power shel ??

gaunt marlin
sinful helm
#

not to mention u still need to code the frontend in javascript, so its not like u are gonna avoid learning js

sinful helm
#

which seems a lot more complicated than just using js + html + css

vestal hound
#

you could say that the only viable backend language is JS

sinful helm
#

never experimented with it too much cuz my friend had a horrible experience just coding a dropdown list while i was already done with a fully functioning website with animations, graphics and backend

vestal hound
#

good for you, I guess

sinful helm
vestal hound
#

...but if said dropdown list was in Python...

#

that sounds like vanilla Django

#

not really sure how popular that is, and it's defo showing its age

sinful helm
#

we had to run an algorithm in the backend which took about 15 seconds to run on mine

vestal hound
#

there are definitely reasons to use other languages

sinful helm
#

and on his it took 60 seconds

vestal hound
sinful helm
#

cuz python was slower than js, also probably cuz he sucks at coding algorithms

#

pythons slower than js too

vestal hound
#

/language

#

type safety

#

better abstractions

#

shrug

sinful helm
vestal hound
#

it's not that simple

sinful helm
vestal hound
#

also, there are complex type constructs that you need effort to emulate in TS

#

although I must say it's getting there

sinful helm
# vestal hound better abstractions

idk if it has better abstractions tbh, maybe it depends on the user, but i always found js to have better abstractions than python cuz u could have finer/easier control with what u wanted to do

vestal hound
vestal hound
#

I mean another language in general

vestal hound
#

you can't do that in TypeScript

gaunt marlin
sinful helm
#

gotta google that honestly, no clue what that is

vestal hound
# sinful helm

and are you actually limited by the speed of execution...?

sinful helm
sinful helm
vestal hound
#

it is rare that you are actually CPU-bound and it's language overhead that's slowing you down

#

and if it is, well

#

you have options.

#

Cython, PyPy, etc.

sinful helm
#

for example, the same code I wrote in c++ ran in 5seconds or so

sinful helm
vestal hound
#

but in any case

#

I'd say

#

if speed is that crucial

#

maybe Go or something would be more appropriate

#

I think that when building a web backend

#

Python doesn't shine particularly well...?

gaunt marlin
#

if speed is what you need, just code in assembly 🤣

vestal hound
#

unless you're working specifically with DS/ML

#

but that's an edge case

stiff karma
#

Can I discuss stuff about selenium here?

vestal hound
gaunt marlin
#

@stiff karma it's related to web so yeah you can

vestal hound
#

but if you're using it for testing then maybe #unit-testing might be more appropriate

stiff karma
stiff karma
#

It's more like fundamentals

#

It's giving me a stale element error

#

Even after I have used it to remove exceptions

sinful helm
#

tbf i got the algorithm to work under 100ms eventually

gaunt marlin
sinful helm
#

it may also be because i dont like python as much, things like unmutable strings, and not being able to have a proper for loop still kind of frustrate me

stiff karma
vestal hound
#

as for mutability...honestly I prefer immutability in all things

gaunt marlin
#

maybe you not discovered everything yet of python, loop in python can have alot of implementation

vestal hound
#

but, yes, that's a preference

sinful helm
vestal hound
#

ah

#

so you mean like changing how the loop variable is updated each iteration?

sinful helm
#

u dont use python to code front end do u?

vestal hound
#

Brython is the only thing that lets you AFAIK and that's experimental

sinful helm
#

hmm

vestal hound
#

yeah in that regard Python is more functional

#

depends on how you want to write your code, I guess

sinful helm
vestal hound
#

like

sinful helm
#

can u do that in python?

gaunt marlin
#

the thing you just post can be doable in python

vestal hound
#

no, "functional" in the sense of "functional programming"

sinful helm
#

afaik u cant, but if u can, thats pretty dope

vestal hound
#

for loops like that are very imperative-style

#

like something you would see in C

sinful helm
#

or C++

#

or java

#

or javascript

vestal hound
#

yeah, generally lower-level languages

sinful helm
#

hmm

vestal hound
#

if you look at FP languages (poster child: Haskell), there are no such constructs

sinful helm
#

thats why i liked javascript, cuz in that, u have for i in array, but u also have for(i=0; i<len; i++)

gaunt marlin
#

you can also access index in python

vestal hound
#

you use different abstractions to approach such problems

#

so, yeah, if you want to write that kind of code then at least in that aspect Python is not suitable for you

sinful helm
#

it like, combines the fine control u have from languages like C++ with the higher level language benefits

gaunt marlin
#

it's based on preference

sinful helm
vestal hound
#

it's just a different paradigm

#

but yes, I suppose JS lets you do that

sinful helm
#

for one of the things i was doing, i wanted to skip the next iteration in the loop

vestal hound
#

continue?

sinful helm
#

so i would need to code a while loop

sinful helm
vestal hound
#

set a flag

#

and continue

gaunt marlin
#

^

sinful helm
#

so u would need to make a bool, and then continue next iteration, then set it back to false

#

which is pepega

vestal hound
#

shrugs

#

again, a tool for every problem

sinful helm
#

probably using a while loop would be easier at that point

vestal hound
#

I'd probably

#

find some other way to solve the problem

sinful helm
#

hmm

vestal hound
#

it's like

#

okay e.g. in FP languages

#

the purer ones

#

there is basically no mutable state

#

AT ALL

sinful helm
#

big oof

vestal hound
#

which is probably not something you would want to work with, right

sinful helm
#

i dont get

vestal hound
#

but there are such paradigms

sinful helm
#

why not have a mutable data structure

#

as well as an option for immutable one?

vestal hound
sinful helm
#

just do both

vestal hound
#

no

#

once you have mutability

sinful helm
#

why not?

vestal hound
#

you take away certain optimisation opportunities

sinful helm
#

makes no sense

vestal hound
#

such as lazy evaluation of everything

#

mutability -> side effects -> no pure functions -> you need eager evaluation

sinful helm
#

i think its the opposite isnt it?

#

cuz once u have immutability, all your code will be less optimizable

vestal hound
#

not necessarily

sinful helm
#

well thats not true either

#

thaats why im saying

#

have option for both

vestal hound
#

no, the thing is

#

if you look at Haskell

sinful helm
#

so if i want to change a single value in the string

vestal hound
#

NOTHING is eagerly evaluated (which is its own problem but I digress)

#

because EVERYTHING is pure

sinful helm
#

i have to reassign the WHOLE string

#

which is o(n)

vestal hound
#

ye

#

not necessarily

sinful helm
#

comparatively, if it was just mutable, i could do it in o(1)

vestal hound
#

it's only O(N) if you need to keep the old string

#

otherwise it can be optimised to O(1)

sinful helm
vestal hound
#

and in fact

#

EVEN if

vestal hound
#

you can optimise away the copy

sinful helm
#

ofc there are

vestal hound
#

and just modify inplace

#

and even if there are

#

there are data structures

#

which are optimised for such use cases

sinful helm
#

otherwise i wouldnt call it replace

vestal hound
#

such that you don't need to copy the string

sinful helm
#

thats what im saying

#

have both mutable and immutable data structures

#

and let the user decide

#

which they wanna use

vestal hound
#

the point is

#

some things are language-level

#

and built around the assumption that data is not mutable

#

at all.

sinful helm
#

for example, have istring which is not mutable

#

and mstring which is

vestal hound
#

and you can have immutable data structures for which modification is constant time, or very close

sinful helm
#

and let the developer deside

#

u are basically taking away functionality that could be there

vestal hound
#

might as well include everything you can think of

sinful helm
#

yes

#

basically

vestal hound
#

which leads to bloat

sinful helm
#

no, u can #include them as needed

#

as in c++

vestal hound
#

it bloats the standard library

#

look at the interface of some of the STL containers

sinful helm
#

sure, but that doesnt matter

vestal hound
#

it's pretty wild

sinful helm
#

not much at least

vestal hound
#

why does it not?

#

something being part of the standard library means it is part of the standard

sinful helm
#

because if its not bloating your program, whats the problem?

vestal hound
#

therefore there are upkeep obligations

#

that is why the C++ standard is so convoluted

sinful helm
#

and its not like python is particularly fast, so even if it did slow down a little, doubt anyone would care

vestal hound
#

and the language is so difficult to pick up

sinful helm
#

its difficult to pick up?

vestal hound
#

I would think that C++ is significantly more difficult to pick up and get good at than most languages

#

pointers are complex for most people

sinful helm
#

hmm perhaps 🤔

vestal hound
#

especially DOUBLE pointers

sinful helm
#

pointers are super useful tho

vestal hound
#

undefined behaviour is scary

#

it's not about usefulness

#

but about user-friendliness

#

they are orthogonal concerns

#

the point is C++ is hard to learn because it is close to the metal AND throws the kitchen sink at you

sinful helm
#

so basically pythons a language thats easy to code in, but not necessarily the best to code in?

vestal hound
#

that's what I would say

#

it's an excellent prototyping language

#

but not really something you want to build a huge project in?

#

I guess you CAN

#

like honestly

#

a super simple task

sinful helm
#

i guess i also particularly have a problem with it cuz we have to make a project in it for our college assignment

vestal hound
#

even for something like JS

sinful helm
#

and its pepega

vestal hound
#

make an array

#

with numbers from 3 to 9

#

and sum them

#

how long does that take?

sinful helm
#

to run or to code?

vestal hound
#

to code

sinful helm
#

idk, a min?

#

less than a min

vestal hound
#

probably something like

sinful helm
#

i pretty much only found it useful for data science and such tbh

vestal hound
sinful helm
#

cuz of all of the useful libraries and math functions and matrices and tensorflow

#

3 to 9 right?

vestal hound
#

ye

#

or any two arbitrary non-0 bounds

sinful helm
#

sum = (3+9)((3-9+1)/2)

#

?

vestal hound
#

no, I mean in JS, with the actual array

#

so you need the array too

sinful helm
#

i would use the AP sum formula

#

since it would be more efficient

vestal hound
#

ye but the point is you need the array and the sum

sinful helm
#

oh ok

#

so like an array of values?

vestal hound
#

yup

#

so like how would you 1. get those values into an array and 2. sum them

sinful helm
#

array.reduce(function(a, b){
return a + b;
}, 0);

vestal hound
#

(reduce is a very FP thing btw)

sinful helm
#

mhm

vestal hound
#

yeah, that's 2; what about 1?

sinful helm
#

not denying that

#

1>

#

?

vestal hound
#

(JS has really nice lambdas btw)

sinful helm
#

yeah it does

vestal hound
#

how do you get array in the first place

#

like

sinful helm
#

tho im not the best at them, still

#

where do u want the array from?

vestal hound
#

in Python it's nice to have just sum(range(3, 9))

sinful helm
#

u mean an array of values 3 to 9?

#

yeah

vestal hound
#

and you can prototype stuff REALLY fast IMO

#

although to be fair

#

JS is quite quick too

#

in terms of dev time

#

but JS also has really weird behaviour sometimes

sinful helm
#

[...Array(6).keys() +3]

vestal hound
#

e.g. coercion to string wy default when sorting

sinful helm
sinful helm
#

thats why i say pythons fucking lit for data science

#

but i doubt id wanna use it for much of anything else

vestal hound
#

well, not actually an error, but that won't give you what you want

sinful helm
#

cuz even if i wanna do something basic like skip the next iteration in the loop, id have to go through a bunch of hoops

vestal hound
#

you could map the result

sinful helm
#

if python had mutable strings and good for loops, it would literally be my favorite language ngl

vestal hound
sinful helm
#

sorry

vestal hound
#

I have almost never had to write that kind of for loop

gaunt marlin
#

what trouble of using a simple 1 line of continue?

vestal hound
#

I will note that Python's strings are bad for in-place modifications, though

#

but then again my question is

sinful helm
vestal hound
#

if you're modifying inplace

#

what is your use case?

sinful helm
#

sec, ill see if i can find my code

gaunt marlin
#

you mean this ?

for i in arrays:
   if i == a:
      continue
   print(i)
sinful helm
#

fuck, i think i lost it

vestal hound
#

no

#

something like this:

for element in data:
    if skip:
        skip = False
        continue
    result = process(element)
    if result is None:
        skip = True
sinful helm
#

i was basically trying to make a calculator that takes a string as input, for example "22x3+33(3x9)" and gives all the steps leading to the answer

sinful helm
#

use while loop instead

vestal hound
#

I was illustrating

sinful helm
#

ik

#

and im just sayin facts

#

lol

sinful helm
#

had to do a lot of string manipulations that would have been easier with mutable strings

vestal hound
#

so basically you're saying

#

you kept mutating that string?

sinful helm
#

nop

#

cuz u dont have mutable strings

vestal hound
#

or rather, you would have

sinful helm
#

even something as simple as trying to add a value to the end of the string

#

means that u have to rewrite the whole string

#

afai can tell

vestal hound
#

probably not the way I would have solved it

sinful helm
#

which doesnt seem efficient at all

vestal hound
#

it's not

sinful helm
vestal hound
#

but that's the consequence of solving it that way

vestal hound
#

shrug

sinful helm
vestal hound
#

or some equivalent

#

yes

#

when building the tree

#

what's wrong with recursion?

sinful helm
#

depends how u implement it i guess, the way i have seen it done seems very inefficient

#

how would u implement it?

vestal hound
#

implement which part

sinful helm
#

building the tree

vestal hound
#

okay, that seems a bit overengineered for this problem unless you're doing it for fun TBH but

sinful helm
#

not sure if python has a tree data struct, if it does, i havent used it yet

vestal hound
#

split the expression into tokens

sinful helm
#

yeah, how would u do that?

vestal hound
#

regex

sinful helm
#

hmm

#

ok

#

btw, does regex use python or c code?

vestal hound
#

depends on the exact grammar of the expressions

#

C

sinful helm
#

fair

#

regex would be efficient then i reckon?

#

or nah?

vestal hound
#

but I think (not sure though) there is also a Python implementation if the C module is not available

sinful helm
#

wouldnt make sense to manually code it in for loops and such

vestal hound
#

well

#

for certain edge cases Python regexes take exponential time

#

(not a problem specific to Python)

sinful helm
#

oof

vestal hound
#

but in this relatively simple case, yes, would be fine

#

but more than efficiency...it would be more comprehensible IMO

sinful helm
#

hmm

#

regex is pretty incomprehensible to me sometimes 😂

#

but ok

vestal hound
#

yeah, they can be

#

the nice thing about regexes is that they can encapsulate logic

sinful helm
#

btw, how would u use regex to tokenize it, the issue too is that u need to split it but still include all the operands

vestal hound
#

yup

#

so first you split into tokens

#

there are 3 kinds, right

sinful helm
#

but thats what im asking 😂

vestal hound
#

parentheses, operators, and numbers

sinful helm
#

how would u still include the numbers and the operators, if u split it, wont one of those be gone?

vestal hound
#

no

#

you can split on boundaries

#

!e

import re

print(re.split(r'(?<=a)(?=b)', 'splitabsplit'))
lavish prismBOT
#

@vestal hound :white_check_mark: Your eval job has completed with return code 0.

['splita', 'bsplit']
vestal hound
#

like that

sinful helm
#

but over there..

vestal hound
#

splitting on the boundary between 'a' and 'b'

sinful helm
#

one sec

#

what if u dont know what b is?

#

cuz u probably dont

vestal hound
#

you might not

sinful helm
#

22+33

vestal hound
#

but you know the class of characters it can be

sinful helm
#

u can have 23+44 too

vestal hound
#

sure

sinful helm
#

is there a class of characters for +-/*^ ?

#

in regex?

#

cuz u can also have

#

22+sin(45)

#

python basically seems like, shove everything into one line and use a bunch of inbuilt functions/libraries to do it (not saying thats a bad thing, tho it reduces the control u have over your own program sometimes imo)

vestal hound
vestal hound
sinful helm
#

hmm

vestal hound
#

this is the philosophy

#

batteries included

sinful helm
#

thats the issue i was running into

vestal hound
#

which can be problematic

sinful helm
#

but then u end up with 1 line code thats basically unreadable

vestal hound
#

because you lose sight of what the abstraction conceals

sinful helm
#

like, the fuck does this even mean 😂

return stringExpression = stringExpression.replace(i, str(evaluateMathFunction(
                    mathFunction, eval(i.split("(")[1].rstrip(")")))))
#

i have no clue 😂

#

and i wrote it lmao

vestal hound
#

!e

import random
import re

operands = ['+', '-', '*', '/']
regex = r'(\d+)([+/*-])(\d+)'
exp = f'{random.randint(0, 99)}{random.choice(operands)}{random.randint(0, 99)}'

print(exp)
print(re.split(regex, exp))
lavish prismBOT
#

@vestal hound :white_check_mark: Your eval job has completed with return code 0.

001 | 29+49
002 | ['', '29', '+', '49', '']
vestal hound
#

hm I should get rid of the leading and trailing spaces

sinful helm
#

yeah probably 😂

vestal hound
#

(which occur because I'm splitting on groups)

#

but yeah that's the basic concept I guess

#

of course if you want to handle parentheses it grows more complex

#

and it would probably make more sense

#

to use a regex to find tokens

#

than split like that

sinful helm
#
import random
import re

operands = ['+', '-', '*', '/']
regex = r'(\d+)([+/*-\(\)])(\d+)'
exp = f'{random.randint(0, 99)}{random.choice(operands)}{random.randint(0, 99)}'

print(exp)
print(re.split(regex, exp))
#

what if u did this?

sinful helm
vestal hound
#

did what

sinful helm
#

and im not gonna use it in the end

vestal hound
#

oh

sinful helm
vestal hound
#

probably not so simple

sinful helm
#

cuz u can have

vestal hound
#

because a parenthesis must be matched

sinful helm
#

22+(2*2)

vestal hound
#

so the grammar is not the same

#

once you have parentheses

sinful helm
#

in js or c++ i could just keep copying into a string till i ran into a "^-+/*()[]{}"

#

and then copy into the next element in the array

sinful helm
#

well, at least thats what i was gonna do

#

but i was also using stacks, probably wouldnt work with recursive trees

#

a friend is asking me for help, so im sorry if i take longer to reply

amber moat
#

basic question: how do i make the transition smooth when maximizing/restoring for all the UI elements in general ?

sinful helm
#

async?

amber moat
#

i tried applying it to body element(to apply to every element) but i don't see any change

sinful helm
#

not sure what that is honestly tbh man

#

i just know that if u dont want your UI to hang during a lot of processing, u either load it off to server side or use async programming to do it

amber moat
#

sorry if i'm not accurate with my terms.

amber moat
sinful helm
#

u would use a library that does it for u

#

or

#

use css

#

(easier to use css tbh, much easier)

#

.divclass {
transition: width 0.5s linear;
}

amber moat
#

and yes im using css

sinful helm
#

so u want it to be instant?

amber moat
#

i tried body { transition:width 1s ease-in-out; }

sinful helm
#

mhm

#

so whats the issue?

#

u dont want it to take time?

amber moat
#

yeah like instant or bit smooth

#

the issue isn't big

#

tbh

sinful helm
#

try less time duration

#

and maybe use linear

#

ease in out will be slow in the start and the end*

amber moat
#

ohh

sinful helm
#

so try transition: width 0.5s linear;

amber moat
#

will simply applying to body apply to everything ?

sinful helm
#

hmm

#

nop

amber moat
#

so i've to do it for every section

#

?

sinful helm
#

probably yeah

amber moat
#

smh

sinful helm
#

but it depends

#

if your sections width is defined by the body

#

for example, width:100%

#

then it will probably adjust to the body too

#

but pretty much everyone uses css grids now, which is what i would also recommend u to use

amber moat
#

i tried linear and 0.5s that makes the main window transition slighttly smoother but within elements don't resize instantly and appear stuck for a sec lol

#

so ig i've to make changes to every element lol

#

and also @import doesn't work for loading local CSS files

#

why ?

sinful helm
#

@import "navigation.css"; like this?

#

never used it so i cant say tbh

#

i always used sass and compiled it into minified css or just used a front end dev framework like svelte or react to manage my css

#

u dont want to create too many files as that increases load times, use sass and compile it into a single minified .css file

#

or just include it directly into your html

amber moat
#

@sinful helm thing is there's no HTML and only css. Is there a simpler way of including local css files into the main CSS, web files work well

loud tide
#

hyyy all

#

pls I need sm help with my django code if anybody can hlp pls dm 😭

amber moat
#

i applied that to some of the components and it improved it very slightly

light gale
#

Hey guys, I have a django related question

#
from django.db import models

# Create your models here.

class Meta:
        db_table="Newpost_db"
        db_table="Newnews_db"

class Newpost(models.Model):
    url = models.CharField(max_length=100,default=None, blank=True, null=True)
    date = models.CharField(max_length=100,default=None, blank=True, null=True)
    desc = models.CharField(max_length=300,default=None, blank=True, null=True)
    target = models.CharField(max_length=100,default='_blank', blank=True, null=True)

class Newnews(models.Model):
    url = models.CharField(max_length=100,default=None, blank=True, null=True)
    date = models.CharField(max_length=100,default=None, blank=True, null=True)
    desc = models.CharField(max_length=300,default=None, blank=True, null=True)
    target = models.CharField(max_length=100,default='_blank', blank=True, null=True)
``` this is my models.py. I'm trying to create a table for my news posts as well as my 'post' posts.
#

I also used django rest to create an API to automatically create these posts, and it all seems to work except for one part:

#

Only one table is made sadly, and 'newnews' table is nowhere to be found. I did the migrations, but I'm unsure what I did wrong.

#

Does anyone know where I can start troubleshooting?

quick cargo
light gale
#

Oh I did not, thank you :))))

inland stirrup
#

what type of website would the following be?

it has login facility
it has articles/blogs that can be written only by admin/owner
i need the name for the type of website so that i can research in future?

light gale
#

If you need a website for articles/blogs which is super easy to setup I'd just go with Wordpress to be honest.

#

Most cloud providers have a pre-installed image for a wordpress website when you host an instance with them, making it reliable and easy to setup.

orchid shadow
#

Hello folks, maybe one of you can help me. I'm fighting with Django's ORM to be able to write the same kind of query as this one:

select id, max(coalesce(last_validation, creation_date)) from transactions group by user_id;

The closest I got is with the following queryset:

Transaction.objects.annotate(last_updated=Max(Coalesce('last_validation', 'creation_date'))).values('user', 'last_updated')

The problem is that the group by clause encompass all the model fields, not the one I select from values

inland stirrup
orchid shadow
#

found my solution, in case it is on anyone interest: Transaction.objects.values('user').annotate(last_updated=Max(Coalesce('last_validation', 'creation_date')))

#

I needed to indicate earlier that I'm interested in user. The values() will force a group by by all unique combination of the given field

light gale
#

I'm not that well versed in this all, so I'm not sure how to help you Ranger, sorry.

#

I tried creating an API for my 'posts(not POST)'/news requests. For some reason, my my posts are being saved, but my news is not.

#

api/newpost is saved, api/newnews is not. Anyone have an idea where I should start looking?

#

they were implemented identically as far as I know

#

Found it! Typo somewhere 😉

azure grove
#

hey all

#

question for you guys if you can help

#

i have a form i'm trying to render onto my homepage, but i want to place the code for the form in another html

#

my views calls that nested html from page

#

my home page includes the nested html page

#

however when i load the server the code, the object doesn't pass into html

spiral shoal
#

Hey, I was creating a web app using flask that uses ml model to generate a file so when a form is submitted by a user with the relevant data I used a function to transfer the data to the model and the file was generated and used the send_file() function to send the file to the user to download but the generation of file is taking 30 secs or more and the page keeps loading as the file is sent after the function call returns which generates the file. The time to create file can't be reduced as model is slow but I don't want this reloading as http response shouldn't take that much time and its bad practice. Can anyone provide me with a alternative?

#

I just want to first render a html file that says generating your file and when file is ready I can send it to the user to download. Please help

haughty turtle
#

@native tide So with React I only have one html file? this being index.html? so if I want to change the content in my webpage entirely this is done by unmouting the current component and mounting a new component on click? So if its like this my url never changes I imagine then, if my url was google.com it will always be google.com no matter where on google.com I am navigating?

native tide
#

@haughty turtle Yep, if you want to have different routes you will use react-router library. It will just show a component when you visit that URL

kindred osprey
#

Hello
I am reading about Django and React integeration. All the videos and blogs that I went through were using "Django rest framework" for building REST API for backend and communicated using AXIOS in frontend.
We can build a REST API on Django without using Django REST framework.
So I was wondering if we could use axios POST/GET in the react frontend and connect it with REST API at the backend which is NOT built using DJANGO REST FRAMEWORK?

haughty turtle
#

I am wondering the same thing also, I am building it without rest, rest seems to be used for serialization purposes I believe

#

I think not using REST is fine, I will be doing the same thing.

smoky terrace
smoky terrace
sinful helm
#

Perhaps, but doubt it, his main language of use was python

#

And he was decent at it and could do other stuff fine

#

Just wanted to avoid having to code in HTML css js but had to learn it in the end anyways

#

But I think he still didn’t use css so the website looked garbage

fallen spoke
#

small question, what does DEFAULT_PERMISSION_CLASSES in DRF actually mean? according to docs every one of the specified classed must be met for the request to be acted on by the server but using IsAuthenticated still allows users who are not signed in. can someone explain what it does?

sinful helm
#

And then he just scrapped it cuz mine was so far ahead in the development process and was a lot more polished

smoky terrace
#

backends are usually either python, java or js frameworks

sinful helm
sinful helm
#

Personal project I guess?

smoky terrace
#

oh, sounds cool

sinful helm
#

Yeah

#

But if u have learnt js HTML css already, I don’t see why u would also use python for the back end, but I guess if u really love python that much

#

¯_(ツ)_/¯

sinful helm
#

Like our college websites 😂

#

For whatever reason they use php even tho it’s a relatively new college

smoky terrace
smoky terrace
sinful helm
#

If u wanted to do frontend/UI based backend then u would still probably just use js or a js framework right?

#

Cuz of dom api or reactive frameworks

smoky terrace
#

yeah, you could use both

sinful helm
#

They use sql for databases and php to fetch em

sinful helm
smoky terrace
#

js and django, I guess the first case is also possible

sinful helm
#

Django for thé backend of UI?

#

How so?

smoky terrace
#

but I also guess the reason people use frameworks is to be more efficient and easier than vanilla js

smoky terrace
sinful helm
#

Isn’t django mostly for server sided backend?

#

Mostly?

smoky terrace
#

for ui, i'm not sure django is used

sinful helm
#

Yeah

smoky terrace
native tide
#

@kindred osprey axios is just a request library similar to fetch, it can be used with any backend

native tide