Forums

migrations error

my ccs and other stuff not loaded i use this path static sections :

URL :

/home/mymug/greatkart-django-main/static

Directory:

/home/mymug/.virtualenvs/venv/lib/python3.9/site-packages/django/contrib/admin/static/admin

See https://help.pythonanywhere.com/pages/DjangoStaticFiles/

run this in venv

manage.py collectstatic and this is from my settings.py

BASE_DIR = Path(__file__).resolve(strict=True).parent.parent

STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR /'static'
STATICFILES_DIRS = [
    'greatkart/static',
]

# media files configuration
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR /'media'

but it's not working

How is it not working? Could you show the error message you get?

.

File "/home/mymug/greatkart-django-main/category/models.py", line 21, in get_url
    return reverse('products_by_category', args=[self.slug])
  File "/home/mymug/.virtualenvs/venv/lib/python3.9/site-packages/django/urls/base.py", line 88, in reverse
    return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
  File "/home/mymug/.virtualenvs/venv/lib/python3.9/site-packages/django/urls/resolvers.py", line 828, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'products_by_category' with arguments '('تراول-ماگ',)' not found. 1 pattern(s) tried: ['store/category/(?P<category_slug>[-a-zA-Z0-9_]+)/\\Z']


2023-05-31 11:41:57,538: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:41:58,370: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:42:08,784: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:42:10,842: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:42:11,322: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:42:28,871: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:42:29,390: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:42:39,297: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:42:49,365: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:43:47,945: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:43:49,120: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:43:54,439: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:44:29,367: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:46:45,697: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:46:54,949: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:46:55,479: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:50:05,103: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:50:08,274: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:50:08,767: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:51:18,786: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:51:19,328: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:55:53,275: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:55:57,446: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:56:50,578: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 11:59:44,723: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 12:00:00,221: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 12:00:00,743: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-05-31 16:29:27,406: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-06-02 18:02:52,719: Not Found: /favicon.ico
2023-06-02 18:02:54,819: Not Found: /media/photos/products/_DSC3282-1.jpg
2023-06-02 18:02:56,610: Not Found: /media/photos/products/_DSC3282-1.jpg

i can see the banner image but product image not is the part not showing and this is the slug i use travel-mug-sport

[edit by admin: formatting]

That first error is telling you that in the file /home/mymug/greatkart-django-main/category/models.py, you're asking Django for the URL for the view with name products_by_category with those particular parameters, but you have not defined that in any of your urls.py files.

Yes, you have used the code correctly. This code will allow Django to serve your media files during development.

i use chatgpt to check my urls.py and above is the answer

also i checked my settings with chatgpt

STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR /'static'
STATICFILES_DIRS = [
    'greatkart/static',
]


MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# MEDIA_ROOT = BASE_DIR /'media'

and give me the same answer but still i can not see my product image and give me this error

/media/photos/products/_DSC3223_copy.jpg 2023-06-05 14:16:05,485: Not Found: /media/photos/products/_DSC3282-1.jpg

Have you set up your static file mappings are per this help page? If so, have you run the Django collectstatic management command?

hear is from web section in dashboard and Static files:

URL: /static/

Directory: /home/mymug/greatkart-django-main/static

and yes i run this command Django collectstatic and i also check if it is in mysql databas hear is the result

mysql> SELECT * FROM store_product; +----+--------------------------------+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+-----------------------------------+-------+--------------+----------------------------+----------------------------+-------------+ | id | product_name | slug | description | price | images | stock | is_available | created_date | modified_date | category_id | +----+--------------------------------+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+-----------------------------------+-------+--------------+----------------------------+----------------------------+-------------+ | 1 | تراول ماگ اسپورت | travel-mug-sport | نگهدارنده دما و سرما بدون ریزش حتی در حالت خوابیده و داخل کیف به دلیل دارا بودن دو لایه اب بندی خوش دست و قابل اعتماد | 220000 | photos/products/_DSC3282-1.jpg | 2 | 1 | 2023-05-31 07:05:37.475305 | 2023-05-31 07:11:37.962308 | 1 | | 2 | تراول ماک قفلی | travel-mug-gafly | محصولی مطمعن و با کیفیت | 200000 | photos/products/_DSC3223_copy.jpg | 5 | 1 | 2023-06-05 09:43:25.098133 | 2023-06-05 09:45:50.496270 | 1 | +----+--------------------------------+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+-----------------------------------+-------+--------------+----------------------------+----------------------------+-------------+ 2 rows in set (0.00 sec)

hear is another thing to say in this url i see photo :http://mymug.pythonanywhere.com/static/images/banners/cover.jpg

and in this url i dont :

http://mymug.pythonanywhere.com/media/photos/products/_DSC3282-1.jpg

Make sure that you have a static files mapping for the media directory.

read it complete and carfully pls

STATIC_URL = '/static/' STATIC_ROOT = BASE_DIR /'static' STATICFILES_DIRS = [ 'greatkart/static', ]

hear is from web section in dashboard and Static files:

URL: /static/

Directory: /home/mymug/greatkart-django-main/static

and yes i run this command Django collectstatic and i also check if it is in mysql databas hear is the result

I did read it and that is how I saw that you do not mention a static files mappping or any Django configuration for /media. See https://help.pythonanywhere.com/pages/DjangoStaticFiles/#media-files

give me an example

An example will be useless because the important part is that your configuration matches the layout of your files. See the help page.

i think i done ti right if you think it otherwise fix it for me pls

We don't have opinions on your set up -- is it working correctly now? If not, provide us with more details (like: how did you set up the static files mappings, what errors do you see in the error log for you web app, etc.), so we could help you.