【问题标题】:ISR not working in django server but in next dev serverISR 在 django 服务器中不工作,但在下一个开发服务器中工作
【发布时间】:2021-05-04 07:02:45
【问题描述】:

您好,我最近遇到了一个错误,当我尝试在 django python 服务器中执行 ISR 时,它失败了,但是当我在下一个开发服务器中执行它时,它可以工作.. 在开发服务器上,当我在 django 管理面板中更新内容时,它在开发中发生了变化服务器,但是在生产模式下,我们使用 django 服务器,它不能在那里工作,有什么解决方案..

index.js

import Head from 'next/head'
import Image from 'next/image'
import Posts from '../comps/Posts'
import styles from '../styles/Home.module.css'



export default function Home({data}) {
  console.log(data)
  return (
    <div>
     {data.map(e=>{
               return(
               <div>
                   <h1 id='data_h1'>{e.username}</h1>
               </div>
               )
            })}
   </div>

 )
}


export async function getStaticProps() {

  const res = await fetch('http://127.0.0.1:8000/userprofile_data/');
  const data = await res.json();

  return {props: {data}, revalidate: 1 };

}

【问题讨论】:

  • 您是否将服务器基本 URL 硬编码为 http://127.0.0.1:8000?部署到生产环境时,这可能不是正确的 URL。
  • 在开发中是的,但在生产中会改变它

标签: django django-rest-framework next.js


【解决方案1】:

const res = await fetch('http://127.0.0.1:8000/userprofile_data/'); 中,您从 localhost (127.0.0.1) 获取,这意味着您的开发计算机。在生产中,它运行在不同的计算机上,因此无法访问。 为了修复它,您需要(据我所知)部署您的 Django 服务器并传递 URL。按照这个路径,我建议你使用环境变量来为开发和生产保留不同的基本 URL。

【讨论】:

    猜你喜欢
    • 2011-03-02
    • 2017-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-30
    • 2015-12-23
    • 1970-01-01
    相关资源
    最近更新 更多