import React from 'react';
import { StaticRouter } from 'react-router'
import { Provider } from 'react-redux'
import ReactDOMServer from 'react-dom/server';
import Store from './store';
export default (Url, Component, Props = {}, Context = {}) => {
return ReactDOMServer.renderToString(
<Provider store={Store}>
<StaticRouter
location={Url}
context={Context}>
<Component {...Props}/>
</StaticRouter>
</Provider>
);
}
import reactRenderToString from './reactRenderToString'
import Component from '../client/routes/Home.jsx';
console.log(reactRenderToString('/', Component))
function getNoun(number, one, two, five) {
let n = Math.abs(number);
n %= 100;
if (n >= 5 && n <= 20) {
return five;
}
n %= 10;
if (n === 1) {
return one;
}
if (n >= 2 && n <= 4) {
return two;
}
return five;
}
alert("4 " + getNoun(4, 'слон', 'слона', 'слонов'));
class SomeFormHandler(FormView):
def form_invalid(self, form):
if self.request.is_ajax():
data = {'status': 'error', 'erros': []}
for field, errors in form.errors.items():
for error in errors:
data['errors'].append({'key': field, 'desc': error})
return JsonResponse(data)
else:
...
$.post($(form).attr('action'), $(form).serialize(), function(result) {
if(result.status == 'ok') {
form.reset();
showAlert('Сообщение успешно отправлено', 'success');
}
else if(result.status == 'error') {
for(var ndx in result.errors) {
if(result.errors[ndx].key == '__all__') showAlert(result.errors[ndx].desc);
$(form).find('[name=' + result.errors[ndx].key + ']').parent().addClass('has-error');
}
}
}).fail(function(xhr, textStatus, error) {
showAlert('Ошибка отправки сообщения');
});
class LoadNewForm(forms.Form):
file = forms.FileField(widget=forms.ClearableFileInput(attrs={'multiple': True}))
def load_new(request):
if request.method == "POST":
newtrack = forms.LoadNewForm(request.POST, request.FILES)
if newtrack.is_valid():
files = newtrack.files.getlist('file')
for f in files:
print(f.name)
data = {"header" : "Успешно загружены",}
else:
data = {"header" : "Ошибка проверки формы",}
else:
data = {
"header" : "Загрузить файлы",
"form" : forms.LoadNewForm(),}
return render(request, "load_new.html", context=data)
{% if form %}
<form method="POST" enctype="multipart/form-data">
<div class="form-group">
{% csrf_token %}
{{ form }}
<input class="btn btn-primary" type="submit" value="Send" >
</div>
</form>
{% endif %}
--config
.scss
лежат в папке./scss
. Тогда в nodemon.json
надо добавить следующее:"watch": [
"scss/**"
]
var url = require('url');
var adr = 'http://domain.ru/images/icon.png?test=132';
var parsedUrl = url.parse(adr, true);
console.log(parsedUrl.host); //returns 'domain.ru'
console.log(parsedUrl.pathname); //returns '/images/icon.png'
console.log(parsedUrl.search); //returns '?test=132'
var queryTest = parsedUrl.query; //returns an object: { test: '132' }
console.log(queryTest.test); //returns 132