小编Irt*_*ain的帖子

图像(媒体)未显示在 django-heroku 服务器上

当我上传图像文件成功上传时,我已经在 Heroku 服务器上上传了我的站点 Django 应用程序,并且根据设置的图像路径也可以正确获取,但是图像没有显示它给错误媒体文件未在服务器中找到这是设置媒体设置

    MEDIA_URL = '/media/'
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
Run Code Online (Sandbox Code Playgroud)

这是在 url.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('UserView.urls')),
    path('caterer/',include('CaterView.urls')),
]
# if settings.MediaAllow:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Run Code Online (Sandbox Code Playgroud)

这是models.py

class TypeofFood(models.Model):
    tyf_id = models.AutoField(primary_key=True,auto_created=True)
    tyf_value = models.CharField(max_length=256)
    tyf_image = models.ImageField(upload_to="typeoffood/", null=True, blank=True,default='default.jfif')
Run Code Online (Sandbox Code Playgroud)

在模板中它像这样获取图像

<center><img src="{{i.tyf_image.url}}" class="img-responsive" style="height: 200px; width: 200px; border-radius:50%" alt="Image of Caterers"></center>
Run Code Online (Sandbox Code Playgroud)

python django heroku

7
推荐指数
2
解决办法
5868
查看次数

反应传单未加载瓷砖和镀金 403 请求错误

我正在使用 react-leaflet 与磁贴供应商 Stadia OSM Bright。当我在本地运行它时显示图块但是当我构建并上传到服务器时它停止加载图块并开始发出请求 403 禁止错误。我有一个 API 密钥,但没有找到将它放入组件的任何解决方案。这是一个代码示例

render() {
const headeris = {"Authorization": "Stadia-Auth "+this.state.authkey}
return (
  <LeafletMaps
    center={[this.state.lat, this.state.lng]}
    zoom={12}
    maxZoom={17}
    attributionControl={true}
    zoomControl={true}
    doubleClickZoom={true}
    scrollWheelZoom={true}
    dragging={true}
    animate={true}
    easeLinearity={0.5}
  >
    <TileLayer 
    url="https://tiles.stadiamaps.com/tiles/osm_bright/{z}/{x}/{y}{r}.png"
    attribution= '&copy; <a href="https://stadiamaps.com/">Stadia Maps</a>, &copy; <a href="https://openmaptiles.org/">OpenMapTiles</a> &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
    />
    {this.state.markers.map((position, index) => (
      <Marker
        key={`marker-${index}`}
        position={[position[0][4], position[0][5]]}
      >
        <Popup>
          <p>{position[0][0]}</p>
          <a href={`/admin/calender/${position[0][2]}`}>Book now</a>
        </Popup>
      </Marker>
    ))}
  </LeafletMaps>
);
Run Code Online (Sandbox Code Playgroud)

leaflet react-leaflet

5
推荐指数
2
解决办法
2069
查看次数

在类组件中使用 React Toast 通知

我是 React 新手,想在我的项目中使用 react toast 通知官方文档,在他们的官方网站上,他们使用 react 钩子并使用它来执行通知,但我想在 componentWillMount 或 componentDidMount 的类组件中使用它。有什么办法可以做到这一点,或者我必须使用其他吐司组件。谢谢。

reactjs react-hooks

0
推荐指数
1
解决办法
3569
查看次数

标签 统计

django ×1

heroku ×1

leaflet ×1

python ×1

react-hooks ×1

react-leaflet ×1

reactjs ×1