Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

Django collectstatic not working


Hello!

I buy Metronic to use with Django, but I find that I can't run python manage.py collectstatic to hash (cache busting) the static files. This is very important in production to full cache static files and have a hash in their names, so the cache is invalidated automatic when the files change (new hast will be calculated).

The way you make Django template is fixing the assets dir in the root of the project and config the same dir as static assets in production. So, I can't run collectstatic to apply the hashs and cache busting because django error indicate the sorce dir is the same output dir for assets.

See https://docs.djangoproject.com/en/4.1/ref/contrib/staticfiles/#manifeststaticfilesstorage

Can I move the assets inside _keenthemes and change the configuration to allow collectstatic works without break your template?

att,
Elieser


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (6)


Hi,

One thing you can try is to move the assets folder inside the _keenthemes folder and change the STATICFILES_DIRS setting in your settings.py file to point to the new location. For example:

# in your settings.py file
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "_keenthemes/assets"),
]

This way, you can avoid the error of having the same source and output directory for collectstatic.

Another thing you can check is if you have set the STATIC_ROOT setting in your settings.py file to a different location than the assets folder. This setting defines where collectstatic will store the collected static files. For example:

# in your settings.py file
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

This way, you can ensure that collectstatic will not overwrite the original static files in the assets folder.

You can find more details about this setting in the Django documentation.
https://docs.djangoproject.com/en/4.2/howto/static-files/

Thanks



Hello!

I try your code, but strong personalization of django gives me another error:

FileNotFoundError at /
[Errno 2] No such file or directory: './assets/media/icons/duotune/arrows/arr061.svg'

In template C:\Users\elies\Downloads\django_demo1\starterkit\_templates\partials\modals\create-campaign\_main.html, error at line 14



Hi Elieser,

Have you tried rebuilding the assets using Gulp from the _keenthemes/tools directory? You can find more detailed information in the documentation.
https://preview.keenthemes.com/django/metronic/docs/getting-started

Thanks



Hello!

I gave up using the Django version because it is not ready for production. I decided to create a Django version based on the HTML template myself. Thanks.



Thank you for sharing your feedback with us. We appreciate your honesty and understanding regarding the Metronic Django version. We're sorry to hear that it didn't meet your expectations.

If are experiencing dissatisfaction, you can request a refund through the Envato Market platform.
https://themeforest.net/refund_requests/new.

We will use your feedback to continue improving our offerings and ensure that our templates and resources better serve our users in the future. If you have any more suggestions or if there's anything else we can assist you with in the future, please don't hesitate to reach out. Your satisfaction is important to us.

Thanks



I faced the same error. but I could mange to solve it. you can take a look at my settings.py below:

STATIC_URL = "staticfiles/"
STATICFILES_DIRS = [
BASE_DIR / "assets",
]
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

don't forget to add this to the urls.py file of the project too

urlpatterns += staticfiles_urlpatterns()


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(