Umut
I had to change the server, but now when I upload the files to the host, I get an error like this
Umut
HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the related configuration data for the page is invalid.
Umut
<system.webServer> <handlers> <add name="djhand" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python31\python.exe|C:\Python31\lib\site-packages\wfastcgi.py" resourceType="Unspecified" />
Umut
Is there anyone to help with this?
Hemant
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.") Logs What I am using is from pathlib import Path import os from django_heroku import settings . . . . . settings(locals()) End of file
Hemant
I commented out my SECURITY_KEY variable
Hemant
on google there are some ways mentioned to randomly create a key and then push it to .env file
Hemant
but now it's not even building and giving me error for static_root as empty
Hemant
i was using staticfiles_dir = [ BASEDIR / 'app/static'] and it was working fine on local machine but in remote production even static_root isn't working python manage.py collectstatic gives File "/usr/lib/python3.10/posixpath.py", line 378, in abspath path = os.fspath(path) TypeError: expected str, bytes or os.PathLike object, not tuple Solved this and answer is number 2
Marcos
solved this by from django.core.management.utils import get_random_secret_key SECURITY_KEY = get_random_secret_key()
you should not use this for production, because security key is used for hashing paswords and sessions, if you change your key any time all passwords and sessions and signings will get useless
M.J ROOHI
Hi all, how can I give login required for static resources in django?
write " @login_required " befor page view method in views.py
Hemant
What approach do you use for using static files in your project?
Hemant
STATICFILES_DIRS = [ BASE_DIR / 'app/static/', ] was working for me locally but in production it doesn't Refused to apply style from 'https://hemant-to-do.herokuapp.com/static/style/main.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
Juan Arriagada 🇨🇱
What approach do you use for using static files in your project?
django development server serves static files during development (locally), but in production the strategy is diferent This can help: https://docs.djangoproject.com/en/4.0/howto/static-files/deployment/#serving-static-files-in-production
Juan Arriagada 🇨🇱
what i do, is to serve them using nginx
Juan Arriagada 🇨🇱
hi btw! im a developer from Chile, nice to meet you all.
Hemant
and styling is also working even I have not set anything for my 'app/static/style/main.css' file
Juan Arriagada 🇨🇱
are you using the built-in server? (python manage.py runserver)
Hemant
project/settings.py STATIC_URL = 'static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static/') app/template/main.html <link rel="stylesheet" href="{% static 'style/main.css' %}" /> actual file at app/static/style/main.css
Hemant
am deploying my code on heroku link: https://hemant-to-do.herokuapp.com
Juan Arriagada 🇨🇱
build-in server does that for you
Hemant
I also added import mimetypes mimetypes.add_type("text/css", ".css", True) in settings.py
Juan Arriagada 🇨🇱
DEBUG= ?
Hemant
If add my css code to html file everything is fine in production
Hemant
DEBUG= ?
DEBUG = os.getenv('DEBUG', False) (provided no value in heroku) exported true locally
Juan Arriagada 🇨🇱
try True in heroku
Hemant
try True in heroku
Lol ok if you say
Juan Arriagada 🇨🇱
try True in heroku
seems that worked
Hemant
seems that worked
no more mime error in console after debug true
Juan Arriagada 🇨🇱
but its because you're using the built-in server... you should use gunicorn or similar. Read the docs.
Juan Arriagada 🇨🇱
https://docs.djangoproject.com/en/3.2/howto/deployment/
Juan Arriagada 🇨🇱
(check the version you're using to match the docs)
Hemant
when I removed style from html
Hemant
debug = true is just supressing Refused to apply style from 'https://hemant-to-do.herokuapp.com/static/style/main.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
kv
What is this error The view myproduct.views.Insertrecord didn't return an HttpResponse object.It returned None instead
Hemant
everything is fine locally but on production it says 403 Forbidden CSRF verification failed. Request aborted.
Hemant
what could be the issue I am accessing SECRET_KEY using environment variable
explod
everything is fine locally but on production it says 403 Forbidden CSRF verification failed. Request aborted.
https://stackoverflow.com/questions/9692625/csrf-verification-failed-request-aborted-on-django
explod
I do have {% csrf_token %} everywhere in form tag
double check all points https://docs.djangoproject.com/en/dev/ref/csrf/#:~:text=How%20to%20use,all%20use%20RequestContext.
Hemant
double check all points https://docs.djangoproject.com/en/dev/ref/csrf/#:~:text=How%20to%20use,all%20use%20RequestContext.
I am seriously fed up of django when it comes to production I've used all these things very carefully I am only using generic, contribs and auth classes for views and also have {% csrf_token %} inside form every form tag
Hemant
I have only 4 forms
Hemant
and all have the token
Hemant
maybe I need some rest and then I'll come up with a stupid mistake
Jabed
http://dpaste.org/nE4K
Jabed
http://dpaste.org/nE4K
here I just want to get all objects from forms.py but error shows that "type object 'request_b' has no attribute 'objects'"
Anonymous
How to show response of generic forigenkey data in serializer ?
Christof
Bot has the fitting right?
Doragonsureiyā
Bot has the fitting right?
What are you talking about?
mukhil
When we change input box in html that data how can call from view (Without click submit button)
mukhil
Anyone can help ?👆
mukhil
😳😭I don't know java
Charly
😳😭I don't know java
Then no hope for you
mukhil
Can you help me sir
Charly
Can you help me sir
No, this group is not about javascript
mukhil
😒
mukhil
Which function using for this purpose
Charly
mukhil
Ok
इमरान عمران Imran
I'm using s3 bucket to serve static files in django app, but the images are not loading up it's showing "The authorisation mechanism you have provided is not supported...." , plz help me
Lucky
Store image in database in django with dateformat
Yuvraj
Hey I'm new to django thing, how can i get started with?
Sukuna
Learn from YouTube check documentation
Doragonsureiyā
Hey I'm new to django thing, how can i get started with?
Looking for Django tutorials? you can follow these three recommended ones: * Official documentation and tutorial * Tutorial from MDN * Tutorial from django-girls
Hemant
maybe I need some rest and then I'll come up with a stupid mistake
such a nice thing I noticed I just can not login with any user from my login template (shows csrf token mismatch) If I directly go to the register form and create a new user there... it logs in with that user, the whole app works fine (adding new tasks in to-do app, editing and deleting tasks all works)
Hemant
Hope this describes my situation well https://stackoverflow.com/questions/70890682/csrf-verification-failed-request-aborted-only-for-login-page
Anonymous
How to use generic forigenkey relationship in serializer
Rohit 007
any one help me iam getting this error TypeError: 'function' object is not subscriptable
Mirco
any one help me iam getting this error TypeError: 'function' object is not subscriptable
You are using a function like a dictionary and you cannot Most probably you have defined a dictionary with the same name of one of your functions
Rohit 007
Okay thanks