I am building a react-native app with a Django backend. I am trying to send a user input image to Django to be saved as an ImageField in Django Models without using REST-FRAMEWORK. How can I do that?
Suppose you have a model called Image then you can save the image using the following way.
from django.http import HttpResponse
from django.core.exceptions import PermissionDenied
def saveImage(request):
if request.POST:
if 'image' not in request.POST:
return HttpResponse('Bad POST Parameters. Please use "image" key')
image = request.POST['image']
Image.objects.create(image=image)
return HttpResponse('Image successfully saved')
else:
raise PermissionDenied
I want to use the new Expo Print functionality with a local HTML document:
import { Print } from 'expo';
const printDocument = require('../../../assets/printouts/document.html');
console.log(printDocument);
Print.printAsync({ html: printDocument });
When I run this with Expo, I get an error and I can see that printDocument is equal to an integer, not a string corresponding to the HTML document I’m trying to import.
On the other hand, if I try just this in React, where I use Webpack with the html-loader plugin:
const printDocument = require('../../../assets/printouts/document.html');
console.log(printDocument);
Then printDocument IS a string corresponding to the HTML document as expected.
So my conclusion is I need to configure Expo in some way to import HTML documents into Javascript strings the way html-loader does with Webpack. Any ideas how? Thanks.
Below is default setting in django.contrib.auth.views.LogoutViews,
template_name = 'registration/logged_out.html'
i configurate my app's urls.py like this:
from django.urls import path
from . import views
from django.conf import settings
from django.contrib.auth.views import LoginView, LogoutView
app_name = 'account'
urlpatterns = [
#path("login/", views.user_login, name="user_login"),
path("login/", LoginView.as_view(), name="user_login"),
path("nlogin/", LoginView.as_view(), {"template_name":"account/login.html"}),
path("logout/", LogoutView.as_view(), name="user_logout"),
path("logoutt/", LogoutView.as_view(), {"template_name":"account/logout.html"}),
]
"template_name":"account/login.html" works properly, but "template_name":"account/logout.html" seems make no difference, what's wrong with my code?
When you use the class-based variant, you pass settings to the view through the .as_view (the so called **initkwargs) method:
from django.urls import path
from . import views
from django.conf import settings
from django.contrib.auth.views import LoginView, LogoutView
app_name = 'account'
urlpatterns = [
#path("login/", views.user_login, name="user_login"),
path("login/", LoginView.as_view(), name="user_login"),
path("nlogin/", LoginView.as_view(template_name='account/login.html')),
path("logout/", LogoutView.as_view(), name="user_logout"),
path("logoutt/", LogoutView.as_view(template_name='account/logout.html')),
]
Otherwise the parameters will end up in the self.kwargs, and the class-based view does not inspect these.
The documentation on the LoginView [Django-doc] mentions this as well as a list of parameters you can pass as **initkwargs.
According to Willem Van Onsem's advice, i found the key problem is i mixed up two way of urlpatterns, like this:
url() and regular expression type in urls.py (I learned in django 1.10.1 tutorial)
from django.conf.urls import url
from django.contrib.auth import views
urlpatterns = [
url(r"^login/$", views.login, {"template_name"="account/login.html"}, name='user_login'),
]
path() type in urls.py(django 2.1 docs)
from django.urls import path
from django.contrib.auth.views import LoginView
urlpatterns = [
path("login/", LoginView.as_view(template_name="account/login.html"),name="user_login"),
]
It's obvious that there be two major difference to note:
url import from django.conf.urls, but path import from django.urls straightly, and path type is new in django 2.0, path seems more simple
in django 2.1, LoginView & LogoutView settings pass on as_view(), compare to older expression views.login, {"template_name"="account/login.html"}, simpler too
I have some PDF files that I need to display in an Aurelia View.
The files are not available by direct link
I have an API function that returns a byte array.
In ASP.Net, I have some control over the response object's headers and content type, and can BinaryWrite the contents into the response.
I can't figure out how to do this in Aurelia.
Any suggestions?
Edit:
I'm attempting to use pdf.js as suggested. Injection in Aurelia fails.
import {inject} from "aurelia-framework";
import {HttpClient} from "aurelia-fetch-client";
import {PDF} from "pdfjs-dist"
#inject(Router, HttpClient, PDF)
export class PDFView {
constructor(router, http, pdf) {
this.router = router;
this.http = http;
this.pdf = pdf;
}
The console displays this error:
Inner Error:
Message: key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?
Inner Error Stack:
Error: key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?
at Container.get (http://localhost:65397/jspm_packages/npm/aurelia-dependency-injection#1.0.0-beta.1.2.3/aurelia-dependency-injection.js:480:15)
at Object.invoke (http://localhost:65397/jspm_packages/npm/aurelia-dependency-injection#1.0.0-beta.1.2.3/aurelia-dependency-injection.js:341:81)
at InvocationHandler.invoke (http://localhost:65397/jspm_packages/npm/aurelia-dependency-injection#1.0.0-beta.1.2.3/aurelia-dependency-injection.js:300:168)
at Container.invoke (http://localhost:65397/jspm_packages/npm/aurelia-dependency-injection#1.0.0-beta.1.2.3/aurelia-dependency-injection.js:564:25)
at StrategyResolver.get (http://localhost:65397/jspm_packages/npm/aurelia-dependency-injection#1.0.0-beta.1.2.3/aurelia-dependency-injection.js:127:37)
at Container.get (http://localhost:65397/jspm_packages/npm/aurelia-dependency-injection#1.0.0-beta.1.2.3/aurelia-dependency-injection.js:501:23)
at eval (http://localhost:65397/jspm_packages/npm/aurelia-templating#1.0.0-beta.1.2.7/aurelia-templating.js:3925:73)
End Inner Error Stack
------------------------------------------------
The import statement must be failing, yet pdfjs appears to load successfully as I receive status 200 for both pdfjs-dist#1.5.294.js and pdfjs when the page loads.
I can find no samples of Aurelia / pdfjs apps.
Repeating: I need to embed the stream as the PDF is not available via HTTP.
I'm not sure where to go from here
As far as I know there is nothing Aurelia-specific about loading pdf files.
You can use pdf.js. It has method getDocument that accepts binary data stored in byte array.
Then you can place a canvas inside your view, load pdf data during view activation and render pages into it using pdf.js after html is attached. For example code check answer by toddmo for this post: Pdf.js and viewer.js. Pass a stream or blob to the viewer
All,
I have been trying to import some sample actionscript package into my flash project.
The sample code is defined in the org.red5.flash.bwcheck package.
In my flash project's (flash 8 and actionscript 2.0) actions frame:
I added these lines at the beginning:
import org.red5.flash.bwcheck.app.*;
import org.red5.flash.bwcheck.events.*;
import org.red5.flash.bwcheck.*;
and add the call to this package in my code
function start()
{
serverURL = settingsManager.getIP();
serverApplication = "live";
clientServerService = "checkBandwidthUp";
serverClientService = "checkBandwidth";
trace("calling connect()");
connect();
}
The connect() is a function defined org.red5.flash.bwcheck.app.BandwidthDetectionApp.
Nothing happens when I test the movie.
I added these paths to both action script 2.0's settings and project preferences:
./org/red5/flash/bwcheck
./org/red5/flash/bwcheck/app
./org/red5/flash/bwcheck/events
when I test or debug movie, the connect() does not seem to be called.
If I called the connect with the full path name:
Then I got a lot of syntax errors about the sample code which should not have errors.
My question is how do I import package and use it in my Actions Frame?
Thanks,
Peter