【发布时间】:2021-10-24 02:55:11
【问题描述】:
我有一个简单的 DRF 项目,我想将它部署在 Pythonanywhere 上。我做了所有想要的配置,你可以在下面看到照片。
但是当我想点击上传的照片链接(底部照片)
this is my api with a picture link
我遇到“在此服务器上找不到请求的资源”。错误(下图)
这是我的 pythonanywhere 媒体配置:
这是我在 settings.py 中的媒体设置:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/pictures/'
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploaded_pictures')
这是我的 urls.py 代码:
urlpatterns = [
path('admin/', admin.site.urls),
path('api-auth/', include('rest_framework.urls')),
path('api/', include('gardesh.urls'))
]
这是我的 models.py 代码:
class Profile(models.Model):
owner = models.OneToOneField(User, on_delete=models.CASCADE)
bio = models.CharField(max_length=150, null=True, blank=False)
img = models.ImageField(upload_to='user/prof',null=False, blank=False)
def __str__(self):
return self.owner.username
class Post(models.Model):
owner = models.ForeignKey(User,on_delete=models.CASCADE)
cover = models.ImageField(upload_to='user/cover',null=False, blank=False)
caption = models.TextField(max_length=250, null=False, blank=False)
title = models.CharField(max_length=40, null=False, blank=False, default='no')
def __str__(self):
return self.title
class Comment(models.Model):
auther = models.ForeignKey(User, on_delete=models.CASCADE)
body = models.TextField(max_length=150, null=False, blank=False)
post = models.ForeignKey(Post, on_delete=models.CASCADE,related_name='comments')
published_date = models.DateTimeField(null=False, blank=False, auto_now_add=True)
parent = models.ForeignKey('self', on_delete=models.CASCADE, blank=True,
null=True, related_name='replys')
您可以在我的 GitHub 上查看我的所有代码:https://github.com/GrandNative/Api-gardesh。 谢谢你的帮助
【问题讨论】:
-
欢迎来到 SO!尽管链接可能会显示您的代码,但请尝试在您的问题中包含相关的 sn-ps,因为链接可能会随着时间的推移而中断。有关更多提示,请参阅stackoverflow.com/help/how-to-ask
标签: django deployment pythonanywhere