developersIndia / saadhan

🔖 saadhan is a resources hub for the r/developersIndia community.
https://saadhan.developersindia.in
GNU General Public License v3.0
40 stars 13 forks source link

App throws a 500 error if no category is specified #38

Closed ghost closed 3 months ago

ghost commented 1 year ago

What happened?

The application throws an error if no category is specified on the /resources endpoint.
For instance, the https://saadhan.developersindia.in/resourceswill throw a 500 error.
This is due to the fact that category is None in this case and no default is specified, essentially resulting in a KeyError.

What browsers are you seeing the problem on?

Chrome

Relevant log output

No response

Code of Conduct

Bhupesh-V commented 1 year ago

I think we can return a default 404 page if the category is somehow none (not possible) and the404 page can be used for the whole website to tackle this.

MohitBansal321 commented 1 year ago

Hey did you want to build the 404 page? or send a request for 404 not found?

Bhupesh-V commented 1 year ago

Hey did you want to build the 404 page? or send a request for 404 not found?

Precisely, we can come up with a 404 page, with a little graphics. Like what github does https://github.com/asda;skjcladbnvabdnv

MohitBansal321 commented 1 year ago

would you like to assign this issue to me

Bhupesh-V commented 1 year ago

would you like to assign this issue to me

Sure LMK if any help is reqd, ask here or on our server

MohitBansal321 commented 1 year ago

Okay I will create the frontend for the not found page 404 but I need some basic knowledge about how you render different html files in base.html file

ghost commented 1 year ago

@MohitBansal321

@app.errorhandler(Exception) def exception_page(error): return render_template('error.html')

Add this one in the main.py and create the page error.html

ghost commented 1 year ago

image

Just a demo.

ghost commented 1 year ago

Okay that's flask thing. It's called Jinja if you want I can show.

On Fri, 17 Feb, 2023, 4:49 pm Mohit Bansal, @.***> wrote:

I need to display the all content of base.html Inside it {% block content %} {% endblock content %} I want to display the Not Found page in between

— Reply to this email directly, view it on GitHub https://github.com/developersIndia/saadhan/issues/38#issuecomment-1434499353, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASZ57AN44S4DZJHP52Q4VDDWX5NDTANCNFSM6AAAAAAUXOLCQU . You are receiving this because you commented.Message ID: @.***>

ghost commented 1 year ago

How about this ? image

MohitBansal321 commented 1 year ago

How about this ? image

Yess

MohitBansal321 commented 1 year ago

Okay that's flask thing. It's called Jinja if you want I can show. … On Fri, 17 Feb, 2023, 4:49 pm Mohit Bansal, @.> wrote: I need to display the all content of base.html Inside it {% block content %} {% endblock content %} I want to display the Not Found page in between — Reply to this email directly, view it on GitHub <#38 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASZ57AN44S4DZJHP52Q4VDDWX5NDTANCNFSM6AAAAAAUXOLCQU . You are receiving this because you commented.Message ID: @.>

Yes please

ghost commented 1 year ago

{% extends 'base.html' %} {% block content %}

Something Went Wrong!!


Return to home page

{% endblock content %}
ghost commented 1 year ago

add this to `{% extends 'base.html' %} {% block content %}

Something Went Wrong!!


Return to home page

{% endblock content %}`
ghost commented 1 year ago

add this in error html file

MohitBansal321 commented 1 year ago

Screenshot 2023-02-17 191011 I do the same already

MohitBansal321 commented 1 year ago

I though how should i send when something is wrong or not found

MohitBansal321 commented 1 year ago

@ansid0102 python3 -m venv venv I install the python and i added the path of python and python script and turn off the Manage App Execution Aliases. but It show the error Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

Python is installed

ghost commented 1 year ago

I think maybe it's because of path not set bro.

MohitBansal321 commented 1 year ago

I think maybe it's because of path not set bro.

Path is set too

ghost commented 1 year ago

I found this stackoverflow try once: Go to -> "start" and type "Manage App Execution Aliases". Go to it and turn off "Python"

MohitBansal321 commented 1 year ago

I found this stackoverflow try once: Go to -> "start" and type "Manage App Execution Aliases". Go to it and turn off "Python"

I already did all the internet solutions

ghost commented 1 year ago

Ohh then I don't know bro. If anyone knows how to figure this out. Please help him out @MohitBansal321 .

jatinb92 commented 1 year ago

@MohitBansal321 Here are few solutions. https://bobbyhadz.com/blog/python-was-not-found-run-without-arguments-to-install

The best one is to uninstall python, remove the path and res install it again.

You can also use pipenv to manage you python project. https://github.com/pypa/pipenv

Please let me know if you need any other help.

yumpyy commented 3 months ago

hello! regarding the fix ghost mentioned here, it handles the exception only when no parameter(s) is/are passed in /resources. when i go to an undefined route something like /foobar, flask throws error due to request made to an undefined path in the /templates/base.html file.

here are the relevant lines from the error.

  File "saadhan/templates/error.html", line 1, in top-level template code
    {% extends 'base.html' %}
  File "saadhan/templates/base.html", line 11, in top-level template code
    <meta property="og:url" content="{{ url_for(request.endpoint, _external=True) }}" />
  File "saadhan/venv/lib/python3.12/site-packages/flask/app.py", line 1978, in url_for
    if endpoint[:1] == ".":
       ^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

edit: replacing url_for(request.endpoint, _external=True) with request.url fixes the issue, but im not sure if there are any downsides of using request.url.

can i make a pr now? here is the error page screenshot image

LinearArray commented 3 months ago

I don't think there are any downsides of using request.url.