How to display ipconfig /all in template html django

111 views
Skip to first unread message

Ramin Farajpour Cami

unread,
Sep 7, 2017, 3:10:16 AM9/7/17
to Django users
Hi,

Hi,

I going to show output command "ipconfig /all" in html django template but i have string uncomfortable,

for example :

i going to show this in html :


Windows IP Configuration


PPP adapter VPN:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::50a6:e568:7895:590d%24
   IPv4 Address. . . . . . . . . . . : 172.32.87.176
   Subnet Mask . . . . . . . . . . . : 255.255.255.255
   Default Gateway . . . . . . . . . : 0.0.0.0



please see image attached,


Capture.PNG

James Schneider

unread,
Sep 7, 2017, 4:08:45 AM9/7/17
to django...@googlegroups.com
In your view, you would need code to execute that command, capture the output, and then provide that output to a variable in your template context. Your template would then access the variable and display the result.

Something like this library may do the heavy lifting of running the command and parsing the results for you. 


A quick Google brought that up. There may be other libraries that interact directly with the Windows internals to pull that information in a bit more of a sane manner, but I haven't looked 

-James

Bernd Wechner

unread,
Sep 7, 2017, 4:14:17 AM9/7/17
to Ramin Farajpour Cami, Django users
Ramin,

I'm sorry but your question is not very clear. How about you capture the output of "ipconfig /all" with something like:

IPconfig = subprocess.check_output(["ipconfig", "/all"], stderr=devnull)

then add Config to your template context in a view something like:

    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)
        context['IPconfig'] = IPconfig
        return context

Though it depends on whether you're using class based generic views or standard views for example, but just look on-line for how to add data to a templates context.

Good luck. But if you want better help, try and be more clear about what you want and how you envisage achieving it I guess, share a description or sample of your template and view etc.

Regards

Bernd.

Ramin Farajpour Cami wrote:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0a2a15a4-6be1-4cde-bbac-a1274330c5da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Ramin Farajpour Cami

unread,
Sep 7, 2017, 5:12:36 AM9/7/17
to Django users
Thanks Bernd,

Your right, but i have problem show in view with output format ipconfig in html,

i try display :

PPP adapter VPN:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::50a6:e568:7895:590d%24
   IPv4 Address. . . . . . . . . . . : 172.32.87.176
   Subnet Mask . . . . . . . . . . . : 255.255.255.255
   Default Gateway . . . . . . . . . : 0.0.0.0


but now i have :

PPP adapter VPN:Connection-specific DNS Suffix  . :Link-local IPv6 Address . . . . . : fe80::50a6:e568:7895:590d%24IPv4 Address. . . . . . . . . . . : X.X.X.XSubnet Mask . . . . . . . . . . . : 255.255.255.255Default Gateway . . . . . . . . . : 0.0.0.0


Do you have idea?

Bernd Wechner

unread,
Sep 7, 2017, 5:35:10 AM9/7/17
to django...@googlegroups.com, Ramin Farajpour Cami
Ramin,

That's an HTML question, and nothing to do with Django. In HTML whitespace all just collapses to a single space, newlines included, and you need to request them explicitly.

You can wrap it all in a <pre> </pre>  tag pair or replace \n with <br> in your string, but that is just two of  a plethora of options (including CSS styling, tables, and more, you can even use Django template filters and tags to to help, literally no shortage of ways to format and render this stuff), and you'd be the one to decide which is best for your desired layout.

No simple answer I'm afraid :-(.

Regards,

Ramin Farajpour Cami

unread,
Sep 7, 2017, 5:49:04 AM9/7/17
to Django users
Thanks a lot it's work.

i use tag <pre style="text-algn:left"></pre>
Reply all
Reply to author
Forward
0 new messages