MIME type error with css file and load static showing in plain text - Django on PyCharm IDE

Out of curiosity, what materials (book, website, videos) are you using to learn Django?

Regarding runserver, that’s not how you run it.

To run runserver, you need to typically use the manage.py command.

See Writing your first Django app, part 1 | Django documentation | Django

Alright that’s the correct one:

Watching for file changes with StatReloader
Performing system checks…

System check identified no issues (0 silenced).
March 12, 2024 - 18:40:49
Django version 5.0.3, using settings ‘YouTrade1.settings’
Starting development server at http://127.0.0.1:8000/

I learnt it at Fordham NYC in 2018 but I never actually deployed anything serious :frowning:
Which is the same for all other programming languages I know (SQL, C++, VB, HTML, CSS) only lots of algorithms, on paper most of them. I’m getting back at it rn, so I need to take off a bit of dust :smiley:

Hi @KenWhitesell ,
what’s your catch on this?

I’m still waiting for an answer to this:

Isn’t this one the answer?

I don’t see the portion of your runserver log where you’re trying to access this.

python3 manage.py runserver

Is there a port I need to specify?

No, it auto-assigns 8000 as you can see in the output.

1 Like

Ok, so how do we progress from here?

Open up your browser, go to that address, and show me the output from the runserver console.

{% load static %}

We help Content Creators

Invest in creators and share their success!

  • Invest in high-growth aspiring creators
  • Support creators on their way to success
  • Collect profit from creators’ revenue
  • Diversify your portfolio

YouTrade

[infoyoutraders@gmail.com]>>(http://localhost:63342/YouTrade1/YouTrade1_App/templates/YouTrade1/infoyoutraders@gmail.com)

©2024 by YouTrade

I need to be sorry about this, I was sure it was inserted before! :pray:

I don’t understand what I’m looking at here - you’ve got this quoted with >> instead of placing this page between the lines of ```.

You still haven’t made it clear what URL you’re entering in your browser address bar.

Also, you haven’t posted the output from the runserver console for this.

Ah ok, here they are, my bad:

{% load static %}
We help Content Creators
Invest in creators and share their success!
Invest in high-growth aspiring creators
Support creators on their way to success
Collect profit from creators' revenue
Diversify your portfolio
YouTrade

infoyoutraders@gmail.com
©2024 by YouTrade

The browser opens automatically when I click debug on my PyCharm. The URL looks like this:

http://localhost:63342/YouTrade1/YouTrade1_App/templates/YouTrade1/YT_Creators.html?_ijt=7v3mgcdshe8isllo0lsf07aft6&_ij_reload=RELOAD_ON_SAVE

The output from the console when I click runserver looks like the one I had previously posted:

Watching for file changes with StatReloader
Performing system checks…

System check identified no issues (0 silenced).
March 12, 2024 - 18:40:49
Django version 5.0.3, using settings ‘YouTrade1.settings’
Starting development server at http://127.0.0.1:8000/

Ok - you’re not going to your server.

I don’t care what you’re doing in PyCharm - that’s meaningless.

If you want to test your page, you open your browser and you go to the url

Ahh ok that’s what I was getting wrong!
If I paste this URL: http://127.0.0.1:8000/

I get

A server error occurred.  Please contact the administrator.

On my PyCharm Console:

Traceback (most recent call last):
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\utils\deprecation.py", line 133, in __call__
    response = self.process_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\contrib\messages\middleware.py", line 12, in process_request
    request._messages = default_storage(request)
                        ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\contrib\messages\storage\__init__.py", line 12, in default_storage
    return import_string(settings.MESSAGE_STORAGE)(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\contrib\messages\storage\fallback.py", line 17, in __init__
    storage_class(*args, **kwargs) for storage_class in self.storage_classes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\contrib\messages\storage\cookie.py", line 92, in __init__
    self.signer = signing.get_cookie_signer(salt=self.key_salt)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\core\signing.py", line 114, in get_cookie_signer
    key=_cookie_signer_key(settings.SECRET_KEY),
                           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\conf\__init__.py", line 98, in __getattr__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\utils\deprecation.py", line 134, in __call__
    response = response or self.get_response(request)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\core\handlers\exception.py", line 57, in inner
    response = response_for_exception(request, exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\core\handlers\exception.py", line 140, in response_for_exception
    response = handle_uncaught_exception(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\core\handlers\exception.py", line 181, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\views\debug.py", line 69, in technical_500_response
    html = reporter.get_traceback_html()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\views\debug.py", line 428, in get_traceback_html
    c = Context(self.get_traceback_data(), use_l10n=False)
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\views\debug.py", line 397, in get_traceback_data
    "settings": self.filter.get_safe_settings(),
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\views\debug.py", line 156, in get_safe_settings
    settings_dict[k] = self.cleanse_setting(k, getattr(settings, k))
                                               ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rinal\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\django\conf\__init__.py", line 98, in __getattr__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.


The message is too long to be posted however :frowning:

And what is that message telling you?

Those were the first rows - technically it ends with

django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
[14/Mar/2024 08:41:23] "GET /favicon.ico HTTP/1.1" 500 59

I have created a secret_settings.py with my secret key in there, and then imported in my settings.py file like this:

from secret_settings import *

It shows an error, no module named ‘secret_settings’

Where is that file located?

Why don’t you add that SECRET_KEY to your settings file?

Isn’t that supposed to remain “secret”, so better to have it uncommitted to my Git, etc?

It is supposed to remain secret. However, this isn’t your “deployment-ready” code you’re working with here.

At this stage of development, we set it to something like:
SECRET_KEY=“This is not really a secret key”
knowing that later, when we start deployment builds, it will be replaced.

(And, if we see that in git, it’s a clear indication of the status of the project.)

But yes, in the long run, it’s better off being handled in a different way.