#web-development

2 messages Β· Page 44 of 1

rustic pebble
#

Yup

#

thanks for reminding me haha

toxic marten
#

Ahah no problem πŸ‘

#

It can happen

#

Can i ask you what is your project CR++?

rustic pebble
#

Eh I am not sure I can talk bout it on here

#

If you want we can dm

toxic marten
#

I was just curious. If its private, no problemπŸ‘

rustic pebble
#

It is kind of an account shop but not exactly

native tide
#

do you guys use adobe xd

#

is it better than figma?

vagrant adder
#

i only used xd

native tide
#

is it free?

#

do you have issues downloading it too?

#

or did you have

rigid laurel
#

It is free. But I had issues downloading it

toxic marten
#

Xd is used only for quick propotype right?

rustic pebble
#

@native tide Adobe XD u mean?

#

@toxic marten Not really, you can export HQ SVGs from there

toxic marten
#

So u mean i can create front end using a drop&drop

rustic pebble
#

Not entirely

#

But basically yea

#

You then have to find a way to make it work backend-ly

#

But I wouldn't suggest using sich software, building a website with bootstrap is easier sometimes than getting in the process of making it on adobe

toxic marten
#

I downloaded it because one day i think it could be useful, for prototyping

#

Yes me too

#

Coding is better

#

I use bootstrap for front end

rustic pebble
#

I dont rly do frotnend

toxic marten
#

But can it be used for prototyping? Because till now i used paper

#

Ok

rustic pebble
#

Although I am surprisingly good at it

toxic marten
#

Do someone know some software for front-end prototyping?

native tide
#

i am currently getting good at frontend

#

yes i mean adobe xd

#

having a lot of issues downloading it

toxic marten
#

I downloaded it but i never used at the moment. I use bootstrap, but when i have to think about the project (how to set the website) i use paper and pen

#

nooo it crash😫

rustic pebble
#

Does anyone know how to add link to local element

toxic marten
#

What do you mean

rustic pebble
#

sec

vagrant adder
#

@native tide yes it is free, downloading wasn't a problem at all

rustic pebble
#

Is there a way I can do that for an element with smooth scorlling

#

scrolling

#

Basically user clicks a button called login and it scrolls him down to the login form

native tide
#

i think with javascript yeh

#

while true (window.fullheight) -=1;

#

idkπŸ˜…

#

with an ease-in-out animation added

rustic pebble
#

I ll do it

#

ez

native tide
#

very nice

toxic marten
#

@native tide im reading what is adobe xd on adobes website. I dont understand if it produced with the idea of do prototype or do real website

native tide
#

heh

#

what did you think though

#

it's for prototypes

#

and i think it works better than pen and paper. I've tried using pen and paper before

#

you can add animations and such

toxic marten
#

πŸ‘

onyx crane
#

hey guys, is someone here who can help me with picking a webframework :) / helping me choose if to use a web framework or a game building framework

native tide
#

What are you trying to accomplish?

#

In any case

#

I also have a question.

#

In Django, I have used user.is_authenticated to remove and show the register/login links based on a login session. But a user can still manually enter those urls and bring up the forms while logged in. I am familiar with the login_required decorator but im wondering if there is an option for opposite

#

I could have a conditional display of content on the templates for login/register and a redirect or something.

#

But I imagine someone has thought of a better way

vestal hound
#

@native tide check if user is not authenticated

#

I do that too, but with DRF

#

so I have a permission that checks if the user is not logged in

native tide
#

I'm not really familiar with what DRF is. In fact the first time I heard of it and searched was earlier today. I only sort of know what REST means. My impression is that it has something to do with the idea that... front end rendering takes a load off the server or some nonsense? Am I way offbase because I am just guessing.

#

I know how to do an {% if not user.is_authenticated %} but thats not the same as the @login_required decorator which just makes it impossible to open the page until you login.

#

Let me look at what happens on other websites if I try to do this.

#

It would be cool if there was a similar decorator to just redirect away from that page if logged in.

#

But you know I could put the condition directly in the view as opposed to the template

#

that would make a lot more sense lol

#

ty

vestal hound
#

okay, basically

#

by default, with templates and stuff, you can theoretically render (generate) a full page in Django and send that to the user

#

all of that runs on your server.

#

another way to do it is to have a backend in Django with DRF (Django REST Framework) that runs on your server, and a frontend in some form of JS that runs on the user's computer.

#

so (simplifying) the frontend sends certain requests to the backend, gets data needed to render the page, and then renders it for the user

#

this separates the rendering (frontend) from the data access (backend)

#

in this case, the frontend checks if the user is logged in and, if so, redirects an attempt to visit the login page to the homepage.

#

and on the backend there's a separate check that prevents logging in again if the user's already logged in.

final citrus
#

In Django

#

Where should I store my own .py files within my project
I have a large method that needs to be called during user creation
this method is stored in its own file where it calls other methods in that file
where should I put this and how should I import it

native tide
#

@vestal hound that's pretty close to what I imagined. I thought that was called AJAX. Or, thats the JavaScript that contacts what in this case would be DRF?

#

I don't know enough JavaScript to really do that. I think that unless your app really needs that JavaScript... that that is wasteful.

#

But for example... I have imagined web games I could create that would be difficult to do without a lot of JS.

#

So in those cases I could see justifying it

final citrus
#

In Django what is the model field that will hold an instance of a class?
I know that you can use models.ForeignKey to point to a model, but what about a class?

valid cypress
#

How to use in Django function that fetch fixtures.

vestal hound
#

that question doesn't really make sense...

#

(part of) the point of Django is to map Python objects (classes and builtin types) to database primitives

#

so a class should be represented by a model.

valid cypress
#

I want to have default rows that is in DB, but function should fetch these.

rustic pebble
#

@valid cypress give an example

valid cypress
#

I have JSON files in server with Dynamic IP, and API with static IP that return Dynamic IP. This function get dynamic ip and do request for JSON, that this add to db by model. This should be done only on first startup.

#

@rustic pebble

rustic pebble
#

On server startup or on client load?

#

@valid cypress

valid cypress
#

On first application startup @rustic pebble

rustic pebble
#

You could have a seperate script that you only run once, there is not reason to implement this into the main app since it is only used once

rustic pebble
#

I am having a problem redirecting the user after payment. Basically when he pays a function on my server is triggered through js. Everything works, user gets registered and redirected but it does not set the token

#

Here is my code:

@app.route('/createuser', methods=['POST'])
def createuserfromregister():
    reply = request.json
    plan = returnid(createorder())
    res = make_response("")
    if plan:
        firstname = reply['fullname'].split(" ")[0]
        lastname = reply['fullname'].split(" ")[1]
        newUser = User(username=reply['username'], password=reply['password'], firstname=firstname, lastname=lastname,
                       plan=plan, premium="no", about="You haven't added an about section yet",
                       joindate=time.now().isoformat(), accountscreated=0, email=reply['email'])
        register = registerhandler(newUser)
        print(register)
        print(style.CYAN(
            ''' 
                                        [NEW PAYMENT]
            ''')+ style.GREEN(
                                        """ 
                                        [USERNAME] :    {}
                                        [FULL NAME]:    {}
                                        [ORDER AMOUNT]: {}
                                        [ORDER ID]:     {}                                                         
                                        """.format(style.GREEN(reply['username']), style.GREEN(reply['fullname']), style.GREEN(reply['price']), style.GREEN(reply['orderID']))))
        return loginhandler(newUser)
#

This is the loginhandler.

def loginhandler(LogUser):
    headers = {'alg': 'RS256'}
    key = read_file('privateKey.pem')
    objectuser = session.query(User).filter_by(username=LogUser.username).first()
    res = make_response("")
    starters = objectuser.firstname[:1] + objectuser.lastname[:1]
    print(starters)
    payload = {'username': str(LogUser.username), 'firstname':LogUser.firstname, 'lastname':LogUser.lastname,'starters':starters, 'aboutme': objectuser.about , 'iat': time.now()}
    print(check_password_hash(objectuser.password, LogUser.password))
    try:
        if objectuser.username == LogUser.username and not(check_password_hash(objectuser.password, LogUser.password)):
            print('Wrong credentials')
            return None
        else:
            print('User {} has been found'.format(objectuser.username))
            token = jwt.encode(headers, payload, key).decode('utf-8')
            res.set_cookie("jwt", jwt, 60 * 60 * 24)
            res.headers['location'] = url_for('login')
            print(token)
            return res, 302
    except:
       print("Wrong credentials")
       return None
frigid egret
#

Hi all. Is it a good time to as a question here regarding Django?

rustic pebble
#

I mean, I just asked.

#

but sure go ahead

frigid egret
#

Ye, that's why I'm hesitant

frigid egret
#

I'm making a pretty simple web store.
Here's my code:

    def total_price(self):
        return sum([item.price for item in self.orderitem_set.all()])

    print(total_price())

The error is:
TypeError: total_price() missing 1 required positional argument: 'self'

#

I get total price in admin panel, cause it's being red like a model field. But not when I want to get it separately.

bleak bobcat
#

Is it a class method ?

frigid egret
#

Yep

#

Class Order, has alot of variables. Should I post it?

bleak bobcat
#

Then you can't call it directly. You need to call it from an instance of your class

frigid egret
#

I am calling it from the instance in post_save

bleak bobcat
#

That's not what I see on the code you posted print(total_price())

frigid egret
#

Oke, 1 second. I was trying to simplify it here

#
def bp_redirect(sender, instance, **kwargs):
    print("INSTANCE", instance.total_price())
#

Like that? Gives me the same error

#

It's outside the class, being called like this:
post_save.connect(bp_redirect, sender=Order)

bleak bobcat
#

Just to be sure, the error you get is pointing to that exact line ?

frigid egret
#

Yes

bleak bobcat
#

try adding weak=False to connect

frigid egret
#

Oh, hold on a sec. If I do it exactly like that, it prints total_price as 0

#

Although in admin panel I can see a proper value in total_price field, so I know the sum method works

#

try adding weak=False to connect
@bleak bobcat Nope, still having 0 for total_price. And it's supposed to be 33

#

So I thought maybe I could transform this function into a variable inside the class? Or is it the wrong way to approach the issue?

tranquil robin
#

I am trying to build a Dashboard like page that will show charts and stuff, and I am using Django.
I want the page to be dynamic, so I will have to call for the data depending on what I click or choose on the front-end.
Now my question is, should I used normal django views or DRF? and why ?

frigid egret
#

@tranquil robin What do you mean by dynamic? Can you give me a specific example? I don't quite see how you can apply DRF outside of making your own admin panel (or view) rather than built it Django admin view. But in that case using Django is a bit redundant in the first place

tranquil robin
#

well, if a chart is showing the data for 2019, and I click on a button and choose 2018, I need to fetch and display that data, without refreshing the page

#

PS: its not the admin dashboard of django

frigid egret
#

I have such view in my project, and it does that without refreshing.

#

Ah, ok...

rigid laurel
#

What you're looking for is AJAX

frigid egret
#

Ok, so you're using template view?

rigid laurel
#

And AJAX necessitates JavaScript

tranquil robin
#

@rigid laurel yes, but with AJAX i will need to "GET" a url, and that URL can be in a "Django View" or "Django Rest API"

frigid egret
#

Can it get data from your database without loading a page, technically?

tranquil robin
#

yes it can

rigid laurel
#

I don't even know which of you needs help. If you're already getting help, thats fine. But I can walk you through what is required to set up the dynamic graph or whatever if you'd like

tranquil robin
#

@rigid laurel I am the one asking for help regarding that topic

frigid egret
#

then you don't need to use DRF necessarily, although that's definitely an option. AJAX looks like a good idea but I can't 100% confirm cause I've never used it. I use JSON, which works pretty well with JS

tranquil robin
#

this is the original question

I am trying to build a Dashboard like page that will show charts and stuff, and I am using Django.
I want the page to be dynamic, so I will have to call for the data depending on what I click or choose on the front-end.
Now my question is, should I used normal django views or DRF? and why ?

frigid egret
#

Yea, you can make JS call Django using JSON or AJAX to get the data it needs to draw

rigid laurel
#

From a high level overview, what you need to do is:

  1. Set up a Django view/url/endpoint that returns the information you want to show in the JSON format
  2. Write some JS that sends a GET/POST request to that endpoint
  3. Load that data into a graph using JS
#

I'm guessing you haven't done step 1 yet?

tranquil robin
#

I understand and know how to do all 3 steps

frigid egret
#

☝️ I was just gonna say that. It's the way to do it, what Charlie said

tranquil robin
#

but my point is that in step 1 , I can create an endpoint using normal "Django View" or "Django Rest API".
Which one is better and why, is my question πŸ™‚

rigid laurel
#

ah alright. If you're building your site with something like React or Vue, then you'd want to use a framework oriented around Rest APIs like Django-Rest, or FastAPI. If you're only having a few JSON endpoints, the rest HTML, then normal Django is fine

#

If I were designing a dashboard. I'd use FastAPI on the backend, and React on the front end

#

FastAPI could be replaced by Django-Rest or by Flask

frigid egret
#

Any will do. But you shouldn't mix them. It's best if you either use only views or DRF. Otherwise it will get more frustrating the bigger your project gets

rigid laurel
#

You don't want to mix the frameworks. But you can serve normal JSON perfectly fine from within Django

#

But it depends how much you're relying on JSON

frigid egret
#

@rigid laurel You seem to know your way around Django. Can you help me solve my current problem perhaps?..

tranquil robin
#

oki will try that out, thanks guys πŸ™‚

frigid egret
#

yw πŸ™‚

rigid laurel
#

I haven't actually used Django in a fair while. Recently I've only used Flask and FastAPI, but those are pretty similar to Django. I might be able to help, if I can't someone else in the channel probably will be able to

frigid egret
#

I hope so, posted it a while ago and didn't get an answer

rigid laurel
#

Probably best to post it again

frigid egret
#

So, I have a pretty simple online store.
In Order object I have method for calculating total price:

    def total_price(self):
        #...calculations...
        return final_price
#

I get that final price in admin panel, it works fine there.

rigid laurel
#

I saw this earlier actually, I don't think I can help, but someone else migth be able to

frigid egret
#

For online payment I'm trying to use post_save method, and it looks like that:

def bp_redirect(sender, instance, **kwargs):
    tp = instance.total_price()
    print("INSTANCE", instance.payment, tp)

So far, it's only to get the total price, not even doing anything with that value.

#

But that method gets 0 as total_price, not the actual value

#

Hope someone else can help me solve it. Should be pretty simple in theory

native tide
#

I'm also having trouble with something involving post_save if anyone notices a problem with this code... I don't really understand it yet. I'm using an example to learn it but its giving me a 502 Bad Gateway

woot@wsi:~/project/users$ cat signals.py
from django.db.modlels.signals import post_save
from django.contrib.auth.models import User
from django.dispatch import receiver
from .models import Profile

@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
    if created:
        Profile.objects.create(user=instance)

@receiver(post_save, sender=User)
def save_profile(sender, instance, **kwargs):
    instance.profile.save()
woot@wsi:~/project/users$ cat apps.py 
from django.apps import AppConfig


class UsersConfig(AppConfig):
    name = 'users'

#    def ready(self):
#        import users.signals

I have the portions of apps.py commented out which stops the Bad Gateway error.

#

To be honest I don't understand what is going on with those decorators enough to even begin to diagnose the problem with this code. So I might just backtrack from using this and read the signals docs.

frigid egret
#

First, you don't need if created, it's post_save, so it does that anyway.

#

uh... I don't quite get the purpose of this code. What are you trying to achieve?

#

@native tide

native tide
#

So... at this point I'm following along with Corey Shafer's django blog tutorial to kind of learn the different features of Django a little better. This is supposed to make it such that any time user registers an account, that it automatically provides them with a profile which otherwise has to be created in the admin page.

the code being used in the guide is here if that helps clarify what is in other files https://github.com/CoreyMSchafer/code_snippets/tree/master/Django_Blog/08-Profile-And-Images/django_project/users

#

But yeah this signals thing is the first thing he has done where I really dont understand what is going on it the code at all.

#

I may have to do some research on decorator syntax before it will make sense to me

frigid egret
#

Ok, so that's a useless example as in, it doesn't have to use signals at all.

#

But I'll try to explain.

native tide
#

I find that tutorial examples sometimes are that way. Thanks.

frigid egret
#

You have a model, say a User

class User(models.Model):
  # User variables...

Then if you want some other action to be done, let's say a notification, you add this below:

post_save.connect(to_do, sender=User)

And then you add a method that makes that notification:

def to_do(sender, instance, **kwargs):
  # notification mechanism
#

Hope that helps πŸ™‚

native tide
#

yes that is more something I can work with to make sense of this at least.

#

So that receiver decorator isnt necessary?

#

Its just an overcomplication?

frigid egret
#

Nope, I suggest you start like that, later you can experiment with decorators if you want. I usually write those methods like that first to ensure they work, and then I change them with decorators when optimizing code

native tide
#

I see how it seems to have the same parameters as your example to_do() though.

#

err

frigid egret
#

But then again, I can't say I've alot of experience with Django

native tide
#

the example post_save.connect()

#

I think I can work with this without the decorator more easily.

#

I'll try it out and see what happens

frigid egret
#

Yep, because it's how program knows where to look

native tide
#

Also...

frigid egret
#

on post_save it tries to find to_do method and executes it. And to_do method on its side takes sender and/or instance from post_save parameters

native tide
#

The way he has us doing this

#
#    def ready(self):
#        import users.signals
#

whats up with that

#

obviously not commented out

#

Is that to avoid circular imports or something

frigid egret
#

Again, the way he does it doesn't make much sense to me =/

native tide
#

Right on haha. He couldnt explain it very well either.

#

Which is weird because thats what he excels at usually

frigid egret
#

It's working code, just probably a bad example to use on

native tide
#

right

#

Well it breaks for me.

#

I get a 502 bad gateway

#

its hard for me diagnose those.

frigid egret
#

I've learned first when was sending users e-mails on registration. A very practical example and there are alot of tutorials online

native tide
#

Ah that was one of the things i wanted to do soon

frigid egret
#

Look in Terminal, it'll tell you what's the problem

native tide
#

So... I have this running on a pretend production server.

#

I'm not sure how to get those same messages you get from the runserver command in nginx

#

im new to server admin as well

#

ill look into it though

#

ty

frigid egret
#

yw. Don't know how to help you here, I'm using PyCharm. You might want to use it as well, and then upload your latest code to the server

native tide
#

yeah, that is definitely what I should start doing. When I first started out with server side code I didnt really understand how to effeciently move files to the right place so I started deverloping in vim in ssh because I didnt know what else to do.

#

But now I know about rsync and all these other tools

#

And I probably should start doing that.

#

The whole idea of the pretend production server is to know how it works.

#

Dont want to have a habit of editing stuff in vim on production server haha

native tide
#

So.. the main reason why I can't develop on my client machine in PyCharm is because..

#

I cannot figure out how to get postgres to accept a conncetion from client. I remember thats why I started developing in vim on the server.

#

I can change it to maybe a sqlite3 on my desktop but it will just be a mess as the data isnt the same.

#

I basically gave up on trying to get it to connect to get postgres server to accept connection from client and I really have no interest in going back to trying to figure it out. I would rather just develop on vim.

#

I spend probably two weeks reading docs and trying postgres config and django configs to do it.

#

And Im just done haha

frigid egret
#

@native tide Did you use pgAdmin?

tired root
#

@native tide You need to allow the connection in pg_hba.conf

#

For my network, the entry looks like this: host all all 10.10.10.0/24 md5

#

the file is in /etc/postgresql/%version%/main/

lofty matrix
#

In Django's admin, you can use autocomplete_fields = ("field1, "field2") to get the Select2 dropdown for a ForeignKey field. Is there any way to get this widget for a TextField with choices? This would just be a normal dropdown of text options rather than a dropdown of other model instances, but with the search box

rustic pebble
#

Can anyone give me an idea on how I can do that with flask?
I mean the easy way, not coding related to db

#

These numbers are just mock ones

#

I used

tired root
#

count sessions

#

before_request and after are your friends

#

rest is just database

#

same goes for accounts created. fill the db with a number everytime someone creates an account, count one up

rustic pebble
#

I have thought of that, but I really believed there was a flask way of doing that

tired root
#

CREATE TABLE t_accounts_daily ( id INTEGER PRIMARY KEY, number INTEGER, day datetime)

rustic pebble
#

god dam it

#

Yea chill I got it

tired root
#

sorry for helping

rustic pebble
#

Np thanks

#

πŸ˜„

toxic marten
#

Bootstrap documentation suggest to do this with btn-group nesting:

#
                    <button class="btn btn-secondary">A</button>
                    <button class="btn btn-secondary">B</button>
                    <div class="btn-group">
                        <button class="btn btn-secondary dropdown-toggle" data-toggle="dropdown">C+</button>
                        <div class="dropdown-menu">
                            <a href="" class="dropdown-item">C</a>
                            <a href="" class="dropdown-item">D</a>
                            <a href="" class="dropdown-item">E</a>
                        </div>
                    </div>
                </div>```
#

But can i do also that: (?)

#
<div class="btn-group">
                    <button class="btn btn-secondary">1</button>
                    <button class="btn btn-secondary">2</button>
                    <button class="btn btn-secondary dropdown-toggle" data-toggle="dropdown">3+</button>
                    <div class="dropdown-menu">
                        <a href="" class="dropdown-item">3</a>
                        <a href="" class="dropdown-item">4</a>
                        <a href="" class="dropdown-item">5</a>
                    </div>
                </div>
#

difference is that first one is nested into another btn-group

#

And aria-labelledby attribute is important for some reason or its just used for screen reader?

native tide
#

@frigid egret no, I use the Django ORM and to some extent PSQL to do my database, again from the server.
@tired root it sounds like you know what you're talking about because that is definitely the file that I was led to. I could never get a config to make it work though. I will try again when I wake up a little bit more. I understand a bit more about client server relations than I did when I started this so maybe I can get it to work.

#

As for the problem I was having yesterday, I found it just by pulling down the code to my PC and opening it up in PyCharm
from django.db.modlels.signals import post_save
That was the problem

#

So maybe it is worth figuring out how to get that client connection

#

@toxic marten don't suggest that accessibility is not important to webdevs. They will tear your head off πŸ˜›

gritty carbon
#

Hey guys can you help me with django not displaying my images on test server?

#

what i have in template :

#
{% load static %}
...
 <img src="{% static 'logo.png' %}" height=30 width=30 class="d-inline-block align-top" />
#
STATIC_URL = '/static/'
LOGIN_URL = '/accounts/login'
LOGIN_REDIRECT_URL = '/'
AUTH_USER_MODEL = 'localusers.LocalUser'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
#

error from server

#
[06/Mar/2020 11:04:08] "GET /static/logo.png HTTP/1.1" 404 1650
jagged lark
#

Have you ran manage.py collectstatic

gritty carbon
#

yep

#

wrong link sry

#

template code was wrong

native tide
#

Did that solve it?

gritty carbon
#

nah

#

just pasted it here wrong

native tide
#

So... on a production server you use gunicorn to proxy pass. On a test development server people often add something to their project url conf

#

Did you do that?

#

Let me find an example of such

#

Do you have something like this

#

in your project urls conf? Look at last line

gritty carbon
#

nope

toxic marten
#

@toxic marten don't suggest that accessibility is not important to webdevs. They will tear your head off πŸ˜›
@native tide sorry i dont understand (in english) what do you mean? Do you say that accessiblity (screen reader) is important or not?

gritty carbon
#

so according to that code i have provided where logo.png should be on my project file structure?

native tide
#

There is a complicated way of doing in production.

#

But that shows the development server way

#

@toxic marten Yes, most developers will consider the screen reader stuff important. Im not sure if the culture is the same where you live, but in my country, its often required to do it.

#

@tired root I'm going to try this. The 192... represents my entire local network. (I think)

#

I'm going to kick the server over before I test it.

#

fun times

#

is it possible that that is the wrong range?

#

192.168.1.66 ---> 192.168.1.254 should be what it is

#

I used ipcalc to get that range

#
● postgresql@10-main.service loaded failed failed PostgreSQL Cluster 10-m
#

Damn, I hate editing server files. Now I cant get postgresql to start even when I edit the file back sigh

#

This is why I gave up before though

#

One day I will remember to snapshot servers before I edit their files.

native tide
#

after editing that file I was only able to get my server starting postgres again by backing up my django app, reloading a snapshot of server, and pulling the django app back down.

#

So... I'll try it again if you have some advice on what to do differently next time.

iron sage
#

could someone help me with CSS

tired root
#

@native tide 192.168.1.66 to 254 is impossible, but if your router is 254, then /24 should be correct. You can get your subnet by typing ipconfig -all or ip a . If it is 255.255.255.0 it is /24. 8 bytes for each octet, so 8*3=24.

native tide
#

Yeah the router is 254

tired root
#

What distribution are you running?

#

Maybe SELinux is acting up?

#

Do you have firewall-cmd?

native tide
#

I actually had to pull the snapshot back of my postgresql server failing to start because in the old snapshot my django app is too outdated. So I tried to pull it down from git but it 502 Gateway Errors. It only works the old version of the app. Its been so long since I have snapshotted that I would rather try to fix postgresql than revert. The 502 gateway errors are impossible for me to fix because they dont give me a reason. Its usually some random syntax error in my django app that causes them.

#

I use ufw

#

its ubuntu 18

tired root
#

Have a look cat /etc/selinux/config and see if it is either permissive or disabled

native tide
#
woot@wsi:/etc/selinux$ cat /etc/selinux/config
cat: /etc/selinux/config: No such file or directory
woot@wsi:/etc/selinux$ ls
semanage.conf
tired root
#

then semanage

#

some platforms have different names

native tide
#

Im not sure what selinux is actually.

tired root
#

Security Enhanced Linux

native tide
#

But somehow I have to figure out what broke psql when I edited the file.

tired root
#

something akin to Windows group policies

native tide
#

Its weird that even putting it back

#

It still doesnt work

tired root
#

putting what back?

native tide
#

So when I edited the pg_hba.cong file and turned the server off... ever since it refused to start postgres on startup

#

I changed the file back and restarted again

#

And it still wont

tired root
#

whats the error?

#

check journalctl -xe after trying to start it

native tide
#
woot@wsi:/etc/selinux$ sudo systemctl start postgresql
[sudo] password for woot: 
woot@wsi:/etc/selinux$ sudo systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: active (exited) since Fri 2020-03-06 12:55:10 UTC; 11min ago
  Process: 1252 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 1252 (code=exited, status=0/SUCCESS)

Mar 06 12:55:10 wsi systemd[1]: Starting PostgreSQL RDBMS...
Mar 06 12:55:10 wsi systemd[1]: Started PostgreSQL RDBMS.
woot@wsi:/etc/selinux$ 

#

okay

tired root
#

it started

native tide
tired root
#

type nmap serverip to check if 5432 is open

native tide
#

ok

tired root
#

DOes it run on that port?

#

just making sure πŸ˜„

native tide
#

wow

#
PORT     STATE  SERVICE
22/tcp   open   ssh
80/tcp   open   http
443/tcp  closed https
5432/tcp closed postgresql
#

it was totally open

#

ive been using it everyday

tired root
#

did you permanent the firewallcommand?

native tide
#
woot@wsi:/etc/selinux$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
5432                       ALLOW       Anywhere                  
Nginx Full                 ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
5432 (v6)                  ALLOW       Anywhere (v6)             
Nginx Full (v6)            ALLOW       Anywhere (v6)         
tired root
#

I am not sure about ufw, but in firewall-cmd you have to type --permanent when adding, so it sticks over restarts

native tide
#

I turn it on and off all the time.

#

And the firewalls says its open

#

it must be closed to this IP

#

hold on let me nmap on server

tired root
#

yeah you need to nmap on the server

#

client is irrelevant

#

outgoing connections are always allowed until explicitly forbidden

native tide
#

yeah im having trouble installing it because of bs give me a second

#

Now im getting 404 on trying to install packages...

tired root
#

I have a hunch

#

hold on

native tide
#

ok

#

Man I dont when I will learn not to edit a system file on a server without making a snapshot.

#

I cant imagine what people do on real servers where that isnt possible

tired root
#

Go to /etc/postgresql/versionnumber/main/postgresql.conf

#

with vim or nano whatever

native tide
#

ok

tired root
#

Scroll down a bit, what does it say in listen_addresses ?

native tide
#
woot@wsi:/etc/postgresql/10/main$ cat postgresql.conf | grep "listen_address"
###listen_addresses = '*'               # what IP address(es) to listen on;
tired root
#

and port is 5432?

#

wait

#

that is disabled

native tide
#

yeah let me look at the entire file

tired root
#

it only listens on 127.1

#

uncomment it and enter your network there

#

I am not 100%, but it should accept the network id

#

192.168.1.0

native tide
#

I really dont know how that happened

#

Even if I get this to work to where I can connect it from a client... I dont understand how I broke everything by editing that file and editing it back. It must have been something that changed in the system coming down and going back up

tired root
#

I can't tell you that either from here πŸ˜„

native tide
#

so just 192.168.1.0 or an entire range?

#

Im not the best at networking

tired root
#

that is the whole network

native tide
#

oh

tired root
#

first IP is always the network id

#

since you have a /24, your network goes from 192.168.1.0 to 255

#

But 0 and 255 are not usable, because the first is the ID and the last one the broadcast address

native tide
#

Right.

#

Well... shit

#

I really cant even concern myself with trying to connect to my database from my client anymore

#

because the more problematic problem

tired root
#

ok but you said you couldn't get any packages with apt either?

native tide
#

let me try again

#
woot@wsi:/etc/postgresql/10/main$ sudo apt install nmap
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libblas3 liblinear3 liblua5.3-0
Suggested packages:
  liblinear-tools liblinear-dev ndiff
The following NEW packages will be installed:
  libblas3 liblinear3 liblua5.3-0 nmap
0 upgraded, 4 newly installed, 0 to remove and 86 not upgraded.
Need to get 255 kB/5,468 kB of archives.
After this operation, 25.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Err:1 http://archive.ubuntu.com/ubuntu cosmic/main amd64 libblas3 amd64 3.8.0-1build1
  404  Not Found [IP: 2001:67c:1360:8001::21 80]
Ign:2 http://archive.ubuntu.com/ubuntu cosmic-updates/main amd64 liblua5.3-0 amd64 5.3.3-1ubuntu0.18.10.1
Err:2 http://archive.ubuntu.com/ubuntu cosmic-updates/main amd64 liblua5.3-0 amd64 5.3.3-1ubuntu0.18.10.1
  404  Not Found [IP: 2001:67c:1360:8001::21 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/l/lapack/libblas3_3.8.0-1build1_amd64.deb  404  Not Found [IP: 2001:67c:1360:8001::21 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/l/lua5.3/liblua5.3-0_5.3.3-1ubuntu0.18.10.1_amd64.deb  404  Not Found [IP: 2001:67c:1360:8001::21 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

tired root
#

what does ip a say regarding ipv6?

#

you shouldn't post that

native tide
#

word

#

its just a virtual server but yeah

tired root
#

but it seem to have a public v6 ip

#

can you ping 2a00:1450:400e:80e::2003?

native tide
#

yes

tired root
#

and google.de?

#

or com

native tide
#

yes

tired root
#

then probably the archive down

native tide
#

I saw some people were uninstall postgres and reinstalling it

#

would that destroy the data?

#

Its all test data at this point but

tired root
#

you still have that entry in pg_hba.conf, right?

native tide
#
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             192.168.1.0/24          md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

I thought one was commented out!

tired root
#

hold on

#

change host to hostnossl

#

and restart, try again

#

another method we could try is to change md5 to trust, but that is iffy

native tide
#

right.

tired root
#

Does the app you use do the md5 hashing?

#

There are all methods listed,check what that program needs

native tide
#

When youy say the app I use, which do you mean?

tired root
#

Or is that your django app?

#

The screenshots?

native tide
#

md5 was working several hours ago. with only this at least from my server host all all 127.0.0.1/32

#

yeah thats the django app

tired root
#

Ever tried something like DBeaver to check?

#

Or use psql from another linux machine

native tide
#

I cant even load my normal app. But the weirdest ass hell thing is when I reload and oldsnapshot it will suddenly work with files that are as far as i can tell the same as the files i am looking at now.

#

Nah not familiar

tired root
#

is your client on Windows or Linux?

native tide
#

Both are linux

tired root
#

Maybe it is the django app, idk

#

networking wise I've tried everything

#

last shot: /etc/hosts.deny

#

but I doubt it

native tide
#

I am pretty close to just loading the old snapshot, cutting my losses, and remebering to never in my life again touch my server without making a snapshot first.

#

ok

#

its a file where everything is commented out.

tired root
#

yeah

#

hold on

#

it just came to me

#

you mentioned this is a vps right?

native tide
#

No, this is just a virtual machine running on my client.

#

VirtualBox

tired root
#

oh ok

#

was about to smash my head on the table

#

because I've been only looking at private IP

#

does the network bridge work?

#

can you ping it from your host machine?

native tide
#

let's try. I mean it was a few hours ago, which I cant let go of. haha

#

So I can ping the virutal host from my actual PC, but if I try to ping my actual pc from my virtual host, nothing

#

I think my server isnt getting internet

tired root
#

ok

#

what is the ip of your client?

native tide
#

I pinged google.

tired root
#

and of the host?

#

as in, private ip

native tide
#

192.168.1.197 -- virtual host,
192.168.1.152 -- client

tired root
#

what does it say in virtual box in the network config?

#

which options?

#

we should change that to a nat'd network

native tide
#

bridged.

#

But ive been using it.

tired root
#

hmm

#

bridged should be able to use internet

native tide
#

it is able to because i can ping 8.8.8.8 from it.

#

It just weirdly cant do a lot of things

tired root
#

which adapter is your vbox using?

#

as in, NIC

#

been a while since I have used vbox

native tide
#

not sure. But I able to ping my client again. Maybe I entered a typo before.

tired root
#

ok, but your issue is not getting in

#

it's the replies getting out

#

so, you need to look at how to make your vbox able to talk to your pc

native tide
#

I see

tired root
#

Django cannot establish a connection because it is not getting an answer

native tide
#

I could try to study the differences between this snap and the snap where the django app will work

#

Thats really all I can think to try

tired root
#

that was pointless, there is not much of a config when using bridged

native tide
#

yeah i saw that

#

Im loading the old snapshot and going to try to see what is different about it.

#

To be honest

#

The amount of work that would go into redoing the things to my django project that I would lost is starting to become an amount of time less than figuring this out

#

Which is frustrating

#

Because I want to know

#

But it is what it is

tired root
#

yeah

#

bust most dbms are inherently hard when it comes to configurating access

native tide
#

I appreciate you trying to help me. And actually, that makes sense. I think what I do want to do is go back to the old snapshot... I will have to rebuild some parts of the app, but before I do that.. I might try to see if I can play with the settings to get the database to connect.

#

Because being able to develop in PyCharm would be great

tired root
#

take an other snapshop before doing that

native tide
#

And if I have a snapshot i can always revert

#

Right

#

I will literally never touch my system files again without making one

tired root
#

But you should be able to export the db

#

via psql

native tide
#

Well all the data is test data i could care less about so

#

not even worth it

tired root
#

ok

#

god my fat fingers

bleak bobcat
#

Ever heard of docker @native tide ?

native tide
#

I have and I should probably learn to use it.

#

What did people do before virtual servers?

#

Did they just regularly destroy everything on accident?

#

And nothing they could do about it?

bleak bobcat
#

They either knew what they were doing (because they destroyed everything by accident plenty of times in the past) or had a sysadmin there to do that for them

native tide
#

Right.

#

Well, I follow several people on social media who are sysadmins and pentesters and they run services that I use and we use together

#

And they tell me the same thing

#

That they only are good at it because they have broken a million servers

toxic marten
#

@toxic marten Yes, most developers will consider the screen reader stuff important. Im not sure if the culture is the same where you live, but in my country, its often required to do it.
@native tide Thank you, can you recommend me some cheat sheet for screen reader html attribute? Its simple, but it's easy to forget about someone. So i just need a list

bleak bobcat
#

And they'll still break some in the future, you never stop learning

native tide
#

This is my first server ever. So. Ive been learning a lot from it.

#

Also, I dont really know @toxic marten sorry. Someone probably does though.

toxic marten
#

@native tide πŸ‘

native tide
#

Still have to wonder

#

How you explain this

#

client, server

#

its an nmap of the server

#

But yeah, like I said when I originally described this problem

#

I tried to do this before.

#

I gave up. This would be the second time I give up on this problem.

#

And just go back to vim developing.

#

shrug. My command line skills are improving haha

#

I'm gonna take a break, thanks for trying to help it taught me a few things.

#

I actually might try to learn how to make a docker image and just do that.

#

@tired root I got nmap on my machine with snap.

#
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http
#

The rest are closed

bleak bobcat
#

Do you have a remote repo for your project somewhere ?

native tide
#

yeah. Its acutally just a practice project, its not even my own design. Its just me going over a tutorial. But I still have it up for backup purposes.

bleak bobcat
#

k, can you send me the repo in PM ? And give me access to it if needed ? I'll make you a docker branch

native tide
#

Is that a hard thing to do? I can probably learn to do it.

#

here, I have it on a privately hosted gitea install that my friend runs and you wont be able to be added to it. Let me open one on github

#

I could make it public probably

#

there is nothing sensitive in it

#

But you wouldnt be able to pull request there

tired root
#

ufw allow from 192.168.1.0/24 to any port 5432

#

ufw allow from 192.168.1.151/32 to any port 5432 only from your host machine

native tide
#

by host you mean the vhost or the actual computer? Sorry the terminology confuses me still haha

tired root
#

host is the real one, guest is the vbox

#

this lets the host access the vbox

#

first one allows the whole network

native tide
#

okay let me see if i can get this right haha

#

Man, I would have gotten so much done today if not for this problem. I guess thats life.

#

To be honest I have still learned a lot of things from this.

#

I just wish I didnt have to have learned this way haha

#

from host, still 5432/tcp closed postgresql

#

It doesnt care about the firewall rules

native tide
#

wellll

#

Look what I found

#
postgres@wsi:~$ /usr/bin/pg_lsclusters
Ver Cluster Port Status Owner    Data directory              Log file
10  main    5432 down   postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
#

I believe I will figure it out, ill let you guys know when I do. You put a lot of effort into helping me and i appreciate it

#

OMG

#

its the permissions of the file that changed.

native tide
#

@tired root since you spent so much time trying to help me with this I though I would show you

2020-03-06 12:55:09.956 UTC [1238] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-03-06 12:55:09.994 UTC [1238] LOG:  specifying both host name and CIDR mask is invalid: ":::q:1/128"
2020-03-06 12:55:09.994 UTC [1238] CONTEXT:  line 100 of configuration file "/etc/postgresql/10/main/pg_hba.conf"
2020-03-06 12:55:09.994 UTC [1238] FATAL:  could not load pg_hba.conf
2020-03-06 12:55:09.995 UTC [1238] LOG:  database system is shut down
tired root
#

the q isn't supposed to be there

#

should say ::1/128

#

unless that is something I don't know about

#

but ::1/128 means localhost and only this address

native tide
#

it looks like I added some random thing to my file I didnt know about while editing it

#

Im such an idiot

#

haha

#

but yeah

#

So the take away from this though

#

Is check the log file

native tide
#

I also fixed the thing where it wouldnt download by writing a new source list file.

#

Its all fixed!

native tide
#

Not only did I fix it. But I am now connecting to the database from my client.

amber furnace
#

I really hope that's not a browser client

stark yarrow
#

Hey. I dont know if this is the correct place to do ask it.
I have an Django app running in the local network that has a view that generates a PDF with a model data.
The user opens the link, the view generates the PDF, save a copy to a local shared folder and returns the PDF in the view as content-type pdf.
The file is saved correctly at the local folder but the client doesn't always receive the PDF in the browser. It throws a TimeoutError.
There are only one person using the app at the moment.
Sometimes it goes super fast and works flawlessly, but most of the times it timesout.
I thought that the issue was because it was saving the PDF first, but I removed it temporarily and the timeout still occurs.

What could the issue be? The file is ~3.8MB.
I don't have any issue opening the pdfs on the computer that is running the server. We are on Wifi but we are not having any connection issues.

jagged lark
#

Your connection is probably to blame

#

Can you try to generate a very little file and do some tests, to see if the issue still occurs?

stark yarrow
#

How little? few kbs?

jagged lark
#

Yes

stark yarrow
#

smaller files has no issue.. im pinging my computer from hers

jagged lark
#

Well, that's probably the fault of the network

stark yarrow
#

thats weird... ok well, thanks

rustic pebble
#

@jagged lark timeout errors probably mean that the file took too much time to upload

native tide
#
if settings.DEBUG:
    for each in [static(settings.STATIC_URL, document_root=settings.STATIC_ROOT),
                 static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)]:
        urlpatterns += each

is this ugly?

rustic pebble
#

I suggest you renting a server for like 2euro and have an ftp service running on it to do such tests, I have experienced same problems are urs

#

@native tide it is :/

jagged lark
#

That's not really pythonic

native tide
#

It looks like this in the editor but yeah

rustic pebble
#

replace document root with sth

#

maybe just leave the param as is since you arent using the kwargs in the other param

#

That's django?

native tide
#

yes. You basically add those to the end of you url config if you're in development server only.

#

I knew it was ugly, that was why I asked.

rustic pebble
#

I always wanted to develop on django but I have found flask very very fast and efficient

native tide
#

mm

#

No experience there yet

rustic pebble
#

you could have a decorator

#

Not sure if django supports it

jagged lark
#

And why not urlpattern.extend([...])

native tide
#

Oh is that a thing?

#

Django still has a lot of things I dont know about

jagged lark
#

Yep it is

native tide
#

thats the biggest thing about Django

rustic pebble
#

something like '@debug` and it will automatically render debugs

native tide
#

It big

rustic pebble
#

I do like:
@authenticated and add everything I want under there

#

it really helps break down your code into parts and saves you from rewriting codes

native tide
#

I'm not super good with decorators yet. The only one I understand in Django that I have used so far are @login_required on views that need user login for them display.

rustic pebble
#

I always use a signed JWT to prevent logout even on browser close, and in order to see if a user is signed in or out I have a jwtdecoder and jwtchecker which need to be called upon every time

native tide
#

I should probably review basics on decorators

rustic pebble
#

So using the decorator is actually very huge

#

@native tide is django async?

jagged lark
#

No it isn't

native tide
#

Im not the best person to ask very specific Django questions as Ive only just started myself.

rustic pebble
#

Oqh

#

okay

#

Does anyone know if there are any async frameworks for backend dev?

#

I really love async and I want to prevent the usage of docker

jagged lark
#

aiohttp have support for creating a server, although it is probably very limited

rustic pebble
#

Yea it is

jagged lark
rustic pebble
#

It is used for socketing

native tide
#

Im having trouble finding docs on the extend you speak of.

jagged lark
#

Yeah, lists docs are kind of shitty

#

Thanks Python..

rustic pebble
#

haha

jagged lark
#

Right here

#

It isn't in the built in types page

rustic pebble
#

Flask seemed very easy at start butnow that I am looking django

#

it looks even easier

#

wtf

jagged lark
#

All the functions other than sort are listed here

#

Flask is way easier than django for sure

#

But it is also way more limited

rustic pebble
#

I dont really mind limitations

#

For example apparently django has a security feature that I would never use

#

and make my own version instead

#

When security is considered I usually go with whats better not whats easier

#

and that is why I always build very very strong infrastructures

native tide
#

okaay its not a django thing?

#

its a list method

rustic pebble
#

sort?

native tide
#

I get it

#

extend

#
dev_server_urls = [static(settings.STATIC_URL, document_root=settings.STATIC_ROOT),
                   static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)]

if settings.DEBUG:
    for static_url in dev_server_urls:
        urlpatterns += static_url

Is this more pythonic?

#

It looks terrible because of how long it is

#

But thats what the kwarg is

rustic pebble
#

that more pythonic

jagged lark
#

Yes it is more pythonic for sure

rustic pebble
#

I am not sure if that is a thing on python but can you like include classes so instead of having to write settings.STATIC_ROOT you would just do STATIC_ROOT

native tide
#

I could save space by only importing the settings i am using.

rustic pebble
#

wait you are importing them from a different file?

native tide
#

yes

#

Django is a million different files. Im not sure if Flask is the same way

#

Its organized chaos

rustic pebble
#

you could just do:

from (filename).settings import STATIC_ROOT, MEDIA_ROOT```
native tide
#

right

rustic pebble
#

Flask is only your files nothing more

#

but my structure is kind of weird

#

haha

#

I have more javascript on my files than python

native tide
#

I eventually need to get to the JavaScript parts of my project but one thing at a time.

#

I am curious though...

rustic pebble
#

These all have subfolders

#

with more subfolders

native tide
#

Can you access info in your database from JavaScript? Like, can I use the Django ORM to organize data that I will access from a JS script?

#

jquery

#

fun times

rustic pebble
#

That isnt wise since javascript same as html and css is viewable by the end client

native tide
#

Right.

jagged lark
#

You can also create a public view using the rest API

rustic pebble
#

I use queries to my db to access data

#

Let me give you an example

#

This requests my server and my server request my db for a limit, then the limit is given back and then it gets set in an element

#
      async function getlimit() {
        const url = '/limit'
        const response = await fetch(url, {
            method: 'GET',
            mode: 'cors',
            cache: 'no-cache',
            credentials: 'same-origin',
            headers: {
                'Content-Type': 'application/json'
            },
            redirect: 'follow',
            referrerPolicy: 'no-referrer',
        });
        dtresponse = await response.json();
        console.log(dtresponse['User Limit']);
        document.getElementById('accnumberrender').innerHTML = limit;
        return dtresponse['User limit'];
    }
    function setlimit(limit){
      document.getElementById('accnumberrender').innerHTML = limit;
      console.log(limit)
    }
jagged lark
#

Like, for a merchant website, you can use some AJAX for the front end that access a public rest endpoint to query objects form the article table

rustic pebble
#

setlimit is smth very very bad i did

#

it was for testing purposes

#

And like this is how it looks on the python part

@app.route('/limit', methods=['GET'])
def sendlimit():
    data=jwtdecoder()
    username = data['username']
    user = session.query(User).filter_by(username=username).first()
    limit = user.dailylimit
    print(limit)
    return {'User Limit':str(limit)}
#

and this how I communicate with my db on python and js

native tide
#

It looks like flask fits into one function with a decorator what django spreads out across at least two/three files. lol

rustic pebble
#

Yea flask is very good at keeping things straight

native tide
#

Well, Django is good at keeping things... modular.

rustic pebble
#

but when it comes to more advanced things, it is a nightmare

jagged lark
#

The rest API is also really good for this sort of thing

rustic pebble
#

I break everything in my code into functions so I dont get confused

#

on my main.py which is where everything gets called and use

#

it has around 400 functions

rigid laurel
#

It looks like flask fits into one function with a decorator what django spreads out across at least two/three files. lol
@native tide
what do you mean by that?

jagged lark
#

400 function in one file?

rustic pebble
#

named exactly what I use, it actually is quite handy because I can correct something from the function not from the main one it gets called

#

@jagged lark I have not implemented them all on there

native tide
#

it has the url conf on the view.

rustic pebble
#

I have seperate things for almost everything but I call them in main.py

jagged lark
#

I mean, you'll be better creating a module instead

rigid laurel
#

Oh sure. But for anything complex, the flask way gets annoying quickly

rustic pebble
#

Each website is different though

rigid laurel
#

and blueprints are much worse than the Django way

jagged lark
#

Or your file will be impossible to navigate

rustic pebble
#

@rigid laurel not really

rigid laurel
#

I dislike blueprints

rustic pebble
#

@jagged lark exactly why I break everything into functions so I can both navigate and tinker anything I want easily

rigid laurel
#

I feel like the Django way leads to generally tidier URL naming

rustic pebble
#

Can you elaborate on that?

native tide
#

I cant comment since I havent tried both yet. I had trouble understanding why django seemed so complicated at first. But its actually genius when you realize how you can plug and play various parts of your project into any other project.

rigid laurel
#

The Django way means your URLs are much more condensed into one place, not just above random functions

rustic pebble
#

That is not really true

#

It solely depends on the way you architect your project

native tide
#

To be fair, you urls in Django can be spread out over multiple url confs which at first seems confusing as shit

rigid laurel
native tide
#

But its actually not

#

Its really genius

rustic pebble
#

Have you used flask?

#

Charlie

rigid laurel
#

I have

rustic pebble
#

I mean use use not simple things

rigid laurel
#

I've only used blueprints and the decorator

#

is there another way?

rustic pebble
#

I find it very convenient if you want to make fast asf websites without the django overhead

rigid laurel
#

I'm not disagreeing there

rustic pebble
#

But to be honest both are shity

rigid laurel
#

I'm just saying, I prefer the tools Django offers for managing URLs

rustic pebble
#

Like Id go with Nodejs if I could

#

But I almost always get sucked back in python

rigid laurel
#

Overall, I feel like for me FastAPI is gonna kill any use I'd have of Flask

native tide
#

I don't know. All I think when I do Django is, "Wow, this is taking care of so many things in the background for me." That I dont think of it as overhead. I think of it is saving a massive amount of time overall.

rigid laurel
#

because I'm practically never serving Jinja

#

I'm not a fan of Node

rustic pebble
#

I have heard that fastapi is increasing in popularity

rigid laurel
#

Express feels pretty shitty compared to Flask

#

and I don't know of anything else

native tide
#

what is REST API?

rustic pebble
#

Well with node you can do the following:
Develop a very very good SYNC website and then use docker spam 15 instances and have instant response

rigid laurel
#

where you serve JSON instead of html @native tide

native tide
#

mmm. Ive seen sites do that.

rigid laurel
#

The modern web architecture is React/Vue/Angular on the front end talking to a RestAPI on the backend

#

very little actual HTML

rustic pebble
#

React is backend as well

rigid laurel
#

no it isn't

native tide
#

I hate JavaScript. I would prefer to have a backend of Python.

rustic pebble
#

oh wait

#

mb

dusk torrent
#

Hey

rustic pebble
#

I got confused

native tide
#

I know that I have to use JavaScript sometimes.

dusk torrent
#

whats up

native tide
#

But I would prefer not to if I dont have to

rustic pebble
#

@native tide you will eventually have to use it in your projects

valid cypress
#

How to make that Django rest api model have reference id to other model and this model in view return it's own content and also second model info (from ref. Id) inside it?

native tide
#

Of course

dusk torrent
#

so, guys can we possibly display a image using Python?

rustic pebble
#

I learned it the hard way

#

@dusk torrent not on console

#

I had a deadline which I needed to use javascript to implement updates on an element

#

and I had to learn. js in 12 hours

dusk torrent
#

So, like see if we have a Python Program that can take numbers from the user and then display the image according to the "if" statement in the program?

rustic pebble
#

and implement a socket connection without async in 3 hours

jagged lark
#

@valid cypress you could use a foreign key

native tide
#

Im okay with JS. Im not practiced with it and it frustrates me because similarly to you I didnt take the time to study it thoroughly. I just kind of slammed it together.

dusk torrent
#

Is this possible?

rustic pebble
#

I might sound ridiculous right now, but vanila javascript is quite easy

#

it is very similar to python

valid cypress
#

Ok, thanks

native tide
#

It is but it throws different errors.

rustic pebble
#

and it helps you implement the features you can

native tide
#

And its weird.

dusk torrent
#

Anyone?

rustic pebble
#

If you have the logic of what you want to do

#

You can do it easily

#

@dusk torrent on native window or browser?

#
from IPython.display import display, Image
display(Image(filename='path/to/image.jpg'))
#

this is for native

rigid laurel
#

I learned JS pretty much via google and w3schools, I'm quite a fan

rustic pebble
#

I bought a book

#

and read it

dusk torrent
#

So, i should use this command?

rustic pebble
#

it is not a command haha

dusk torrent
#

then?

native tide
#

I know from experience with my mind that when I start something new that is slightly different from what I prefer, I find every reason to complain about it. But over time.. I open my eyes to realizing it was all me.

#

So knowing that about me...

rustic pebble
#

But to be honest this is not for webdev so you might as well ask in one of the #help channels

native tide
#

I think I will get used to in time.

dusk torrent
#

ok

#

lemme check there

rustic pebble
#

@native tide btw learing js doubles down as c# as well kinda

#

it is exactly same syntax

#

except linq

native tide
#

yeah the syntax I more or less get. Es6 stuff still blows my mind sometimes and makes me have to reference.

rustic pebble
#

fucking microsoft dude

native tide
#

But regular old JS I know the syntax of fine

#

Im just not practiced in building anything big

rustic pebble
#

Nah me neither but I am looking of doing electron-react for my next project

rigid laurel
#

arrow functions are pretty great in JS

#

I'm not a fan of the way it does spreading

native tide
#

I just want to continue using Django for my backend and somehow still be able to have interactive experiences in JS.

rustic pebble
#

You will have to do that

native tide
#

But I haven't got that far yet. Im still learning Django

rustic pebble
#

if you really want dynamic websites

native tide
#

I just dont want a backend of JavaScript though at all.

rigid laurel
#

IMO, as soon as you're doing AJAX, you probably should just shift towards using React or Vue for the entire frontend

rustic pebble
#

.NET is such a great function

native tide
#

I am fine with it on front end

rustic pebble
#

if it werent for that

#

I use fetchapi tbh

#

straight as fck

rigid laurel
#

You still use the fetch api in React

#

just updating things is much easier

#

with props and state variables

rustic pebble
#

y

#

ye

native tide
#

I'm really not sure what JS frontend framework to look at when I get there

rustic pebble
#

I really need to get done with my website

native tide
#

They seem to fall out of favor so quickly

rustic pebble
#

and I am talking here god damn it

native tide
#

I do that all the time

rustic pebble
#

This channel is addicting

rigid laurel
#

I'd say React

rustic pebble
#

I'd say React
@rigid laurel me too

rigid laurel
#

also, the only one that I know of thats fallen out of favour is Angular

native tide
#

I have heard many people express disgust with angular

#

I'll look at react when Im ready to

rustic pebble
#

haters of js

rigid laurel
#

I've used angular a tiny bit, and it seemed about as good as react; but I havent used angular enough to say

#

main reason I'd go for react is that its the most popular - so if you want to get employed or work with others, its good to know

rustic pebble
#

Just learn eveything

native tide
#

I mean, over time I probably will. This is what I do for fun. lol

rustic pebble
#

This is kinda what I follow for backend

native tide
#

Its just that ive only just started

rustic pebble
#

And this is what I follow for front end

#

It really narrows down what you can choose

#

and helps you build with the tools you need

rigid laurel
#

You definitely don't need to learn a lot of this

rustic pebble
#

yea

rigid laurel
#

but its a pretty good overview

rustic pebble
#

only what you need

#

I need to change to nosql dbs

#

But sql is also addicitng

#

I am a web addict

rigid laurel
#

screw nosql

#

well

native tide
#

Going over that frontend progression

rigid laurel
#

maybe not redis

#

but Mongo belongs in the bin

rustic pebble
#

:/

#

Our opinions differ there

native tide
#

I definite got stuck trying to use packages in my project from npm that use webpack because i did not understand webpack. I had trouble with cors, too.

rigid laurel
#

cors is a neverending problem

#

or corsy issues

native tide
#

But... I didn't read books thoroughly about these things the way I did with Python.

#

I just kind of threw myself at it.

rustic pebble
#

I learned python when I was 15

#

by trying to hack Hahaha

#

But then I thought that if I was to hack I would need to first get good at the language

#

and so forth here I am now

native tide
#

It happens.

rustic pebble
#

Never done anything bad in my life

#

I have built many websites never have I done something smelly

native tide
#

Now if you want to be a 1337 hax0r you just install kali and use someone elses python tools haha

rustic pebble
#

I had made some tools tbh

#

never used them

#

I was thinking of going back to cracking game accounts and was planning to build software for that

#

but as I said

#

web dev is addicting and couldnt do it

native tide
#

I have friends who are pentesters who want me to play CTF with them, but I tell them that Im just more interested in development.

#

They dont do anything bad but they are definitely hackers.

rustic pebble
#

Where I am from ctfs and generally coding contests are not a thing

#

and it is quite disappointing

#

In the capital they hold web dev contests and I am planning to go in one though

#

one man team, I can build a super complete website in 2 days max

#

for sure

native tide
#

mm. Speaking of that, I should get to work. lol

#

But thanks for the talk

rustic pebble
#

haha me too

#

See ya, thank you as well

native tide
#

Okay so... what was said earlier about REST being serving JSON... This got me to thinking.

#

I can dump data that I want to use on front end to a json from the database, using python. This data isnt sensitive data about users. Its just that its easier for me to organzie certain things using the ORM in Python.

#

Does that make sense?

#

Basically Im wanting to make a webgame. It's fairly RPG like and based on text based games played in console, only its on the web in a fake JavaScript console.

#

I somehow need to get game mechanics from the back end to the front end because I would rather not program it in JavaScript.

#

Just the interface in JS

#

for example, this is a basic example to make sense of what im saying

#

Say you have character with your logged in account. That character has three items and the ability to cast magic missile. Just for examples sake.

#

That's information in the database I need to relate to the JavaScript frontend to display it

#

Because the interface is a fake JavaScript terminal

#

it's actually a cyberpunk themed game so its made to seem like you're a console cowboy from something like neuromancer

rustic pebble
#

@native tide yea thats good

#

Question: I am refreshing an element with javascript when user clicks submit. The data gets updated and everything but the element value doesnt change

mild merlin
#

@rustic pebble what's the code?

rustic pebble
#

backend or frontend?

mild merlin
#

frontend

#

also what do you mean by "refreshing"

rustic pebble
#

this is what I am using rn

#
      async function getlimit() {
        const url = '/limit';
        const response = await fetch(url, {
            method: 'GET',
            mode: 'cors',
            cache: 'no-cache',
            credentials: 'same-origin',
            headers: {
                'Content-Type': 'application/json'
            },
            redirect: 'follow',
            referrerPolicy: 'no-referrer',
        });
        dtresponse = await response.json();
        console.log(dtresponse['Limit']);
        limit = document.getElementById('accnumberrender').innerHTML;
        limit = dtresponse['Limit'];
        return document.getElementById('accnumberrender').innerHTML = limit;
#

So every time getlimit gets called

#

it should ideally refresh the value of accnumberrender

mild merlin
#

right

rustic pebble
#

It works once

#

but then it just resets to what it was in the start

#

even though the database gets updated

mild merlin
#

limit gets set to the content of accnumberrender first, and then it gets overwritten with the value of dtresponse['Limit']

#

hmm idk

rustic pebble
#

oh right

#

not I can do that

#

let me try doing this:

#
document.getElementById('accnumberrender').innerHTML = dtresponse['Limit'];
mild merlin
#

yeah that might work

rustic pebble
#

I should set it as var

#

maybe

#

Because I want limit to be the elements value so I can set it

#

For some reason it breaks

#

when I do that

native tide
#

{% if (g.permissions & 0x20) == 0x20 %} this throws a syntax error

#

Anyone know how to do a bitwise operation in a flask if statement

native root
native tide
#

Do you know a way to do bitwise at all in flask @native root

native root
#

Yes, you set up a filter that does the operation for you

#

Let me..

native tide
#

I got it

#

I figured out to do this shit in the app.py file

native root
#

πŸ‘

#

in the future, there's a method to define functions you can access in your templates, so you could do {% if permissions(0x20) %} or w/e

native tide
#

alright thanks

native tide
#

anyone know why this would be doing this

rustic pebble
#

CSS problems

#

eh

native tide
#

Well i figured that much lmfao

rustic pebble
#

Getting KeyError: <Response streamed [200 OK]> when trying to upload a file using flask

#

any ideas?

#

Full traceback ^^^

tired root
#

I have already told you a few hours ago, the error is at the bottom

#

@rustic pebble

rustic pebble
#

Yeah but in my defense

#

This is all the code I have upload = send_from_directory(app.config['UPLOAD_FOLDER'], 'accounts.txt',)

tired root
#

there is a comma to much at the end

rustic pebble
#

still same error tho

tired root
#

is that really all code?

#

Because 200 is not an error

#

it's the HTTP code for OK

rustic pebble
#

Let me send you the whole function I have

#

but this is the part that generates the code because before I added that

#

it worked just fine

tired root
#

yeah well now it does not

rustic pebble
#
@app.route('/accrequest', methods=['POST'])
def accrequest():
    session.flush()
    data = request.json
    print('Text Data = ' + str(data['txt']))
    send_text = data['txt']
    clientaccnumber = data['accountnumber']
    upload = None
    try:
        dt = jwtdecoder()
        user = session.query(User).filter_by(username=dt['username']).first()
        print(user.dailylimit > clientaccnumber)
        if user.dailylimit > clientaccnumber:
            try:
                if clientaccnumber < plangrabber():
                    server = data['server']
                    print(server, clientaccnumber)
                    response = accountextractor(server, clientaccnumber)
                    addaccountstodb(clientaccnumber, user)
                    if send_text:
                        accountstotext(response)
                        try:
                            upload = send_from_directory(app.config['UPLOAD_FOLDER'], 'accounts.txt')
                        except Exception as e:
                            print(str(e))
                        print('---Upload added---')
                else:
                    response = {'accountnumber': -1, 'error': 'Exceeded account maximum'}
            except:
                response = {'accountnumber': 0, 'error': 'Please enter the correct details.'}
            print(response)
        else:
            response = {'error':'account limit has been exceeded'}
    except:
        session.rollback()
        response = {'error': 'An unknown database error has occured.'}
    return response, upload
tired root
#

I don't think you can return a tuple there

rustic pebble
#

hmm

#

Thing is that Ii want to get both the response as I utilize it on the frontend

#

and the .txt

tired root
#

Then put that code into a function

#

But from a route, you can only return a response

rustic pebble
#

Damn

tired root
#

I mean, you are returning json here

#

why not put the value into the json?

rustic pebble
#

Because I have two options

tired root
#

{'error': 'An unknown database error has occured.', file: "answer.txt"}

rustic pebble
#

So if a user has clicked export in .txt

#

I want the data to be upload by the server and downloaded by the client

#

while also being added to a table I have

tired root
#

where do you upload it from?

#

from the browser?

#

why upload it at all then?

rustic pebble
#

This is a website

tired root
#

no shit

rustic pebble
#

the user based on criteria makes a search

#

the search returns some shit

#

The shit is displayed as an html board

#

which is made by js

tired root
#

So you mean you send the search query to the server?

rustic pebble
#

Yup

tired root
#

Ok, that isn't an upload

rustic pebble
#

No no

#

When the user clicks submit a query is made and the response is posted back to the user

#

I have added the export in .txt functionality which means that the user will both get the table with the data and download the file

tired root
#

Then why not just return a template with a download link?

rustic pebble
#

Hmm

tired root
#

But anyway, just put the download link in the json and let js display it

#

if you are doing the js route

#

Bottom line: you cannot return a tuple

rustic pebble
#

So there isnt a way to do this: user clicks submit => file starts downloading

tired root
#

There is, you need to return a send_from_directory()

#

from flask

rustic pebble
#

upload = send_from_directory(app.config['UPLOAD_FOLDER'], 'accounts.txt')

#

thats what I am using

#

I will figure it out

#

maybe I will just add two js requests

#

one after th eother

tired root
#

yes, but it needs to be a response

rustic pebble
#

So how should I format it?

#

{file: upload}?

tired root
#

send_from_directory must be returned from the function

#

Do you understand how http works?

#

You cannot just start a download in the middle of your code

#

you need to tell it to the browser

rustic pebble
#

I havent rly used flask to send/get files before

#

I got it

tired root
#

HTTP relies on reponses, such as 404 or 199

#

or 299 and 304

#

All that are responses

rustic pebble
#

I know I use them all over my code

tired root
#

the browser only does something if it gets data from you

#

so, to start a download you need to make a response

rustic pebble
#

Hmm