我在访问 json 文件中的本地图像 url 时遇到问题。以下是我尝试过的所有方法,但没有一个有效。
// json
{
"image": "./images/example.jpg",
}
// React Native
import data from './data.json';
const URL = JSON.stringify(data.image)
<Image source = {{uri: URL } style = {{ width: 98, height: 22 }} /> // Image not showing
const URL = data.image
<Image source = {{uri: URL } style = {{ width: 98, height: 22 }} /> // Image not showing
Run Code Online (Sandbox Code Playgroud)
上述方法中图像未显示。
我也尝试使用 require 如下:
// json
{
"image": "example.jpg",
}
const item = data.image
<Image source …Run Code Online (Sandbox Code Playgroud) 我正在使用 Django 和 React,我正在实现一种当用户忘记密码时重置用户密码的方法。我的基本想法是:
1) 用户提供他们的电子邮件地址
2) 向他们的电子邮件地址发送一封电子邮件,其中包含重置密码的链接(使用 SendGrid api)
3) 用户输入新密码以重置密码
下面是我的序列化器、视图、url 和 React 代码
//views.py
class PasswordResetConfirmSerializer(serializers.Serializer):
new_password1 = serializers.CharField(max_length=128)
new_password2 = serializers.CharField(max_length=128)
uid = serializers.CharField()
token = serializers.CharField()
set_password_form_class = SetPasswordForm
def custom_validation(self, attrs):
pass
def validate(self, attrs):
self._errors = {}
try:
self.user = UserModel._default_manager.get(pk=attrs['uid'])
except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist):
raise ValidationError({'uid': ['Invalid value']})
self.custom_validation(attrs)
self.set_password_form = self.set_password_form_class(
user=self.user, data=attrs
)
if not self.set_password_form.is_valid():
raise serializers.ValidationError(self.set_password_form.errors)
return attrs
def save(self):
return self.set_password_form.save()
// serializers.py
class PasswordResetConfirmView(GenericAPIView):
serializer_class …Run Code Online (Sandbox Code Playgroud) 我正在使用 react 发送电子邮件:
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.REACT_APP_SENDGRID);
const msg = {
to: 'test@example.com',
from: 'test@example.com',
subject: 'Sending with SendGrid is Fun',
text: 'and easy to do anywhere, even with Node.js',
html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
sgMail.send(msg);
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Access to fetch at 'https://api.sendgrid.com/v3/mail/send'
from origin 'http://localhost:3000' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check:
The 'Access-Control-Allow-Origin' header has a value 'https://sendgrid.api-docs.io' that is not equal to the supplied …Run Code Online (Sandbox Code Playgroud)