I have a UIWebView that simply displays a website with the following code:
let str8REDURL = URL(string: "https://str8red.com/")
let str8REDURLRequest = URLRequest(url: str8REDURL!)
webView.loadRequest(str8REDURLRequest)
The page is driven by Django on the backend that handles login authentication. Is it possible to retrieve the django user id from and display it as a message within the app?
I know within the HTML i can just use {{ user.id }}.
If the user is not logged in the message could just say "Not Logged In".
I am using Swift 3. Any help would be amazing.
Django can generate the page with the data you need and store it in a JS variable:
<script>myData = {{ user.id }}</script>
Then you can access this something like that:
let myData = webView.stringByEvaluatingJavaScript(fromString: "myData")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With