Niloofar24 15 Posting Whiz

I don't know how but the problem fixed after rebooting system.

Niloofar24 15 Posting Whiz

models.py:

from django.db import models

class Publisher(models.Model):
    name = models.CharField(max_length=30)
    city = models.CharField(max_length=60)

views.py:

from django.http import HttpResponse
import pymysql
from books.models import Publisher

def send(request):
    p = Publisher(name='Apress', city='Berkeley')
    p.save()

urls.py

from niloofar.views import send

url(r'^index/', send),

I want when the page index is loaded, the send function works and insert data to database but it does not give any error and also nothing happened when i refreshed the index page.

Niloofar24 15 Posting Whiz

Hello. I want to insert data into django db from a function in the views.py file.

I'm using linux, python 3.4, django 1.8.2, PyMySQL

Niloofar24 15 Posting Whiz

I found the answer myself:
pip install Django==1.8.2

Django==1.9.2 Does not support some commands.

Niloofar24 15 Posting Whiz

Hello.
With running this command:
python manage.py validate
I faced with this error:
Unknown command: 'validate'

What should I do now?

For more explanations:
- Linux
- Virtualenv
- Python 3.4.3+
- Django (1, 9, 2, 'final', 0)

Niloofar24 15 Posting Whiz

Hello.
How can I config django (python framework) with mysql? How can i use phpmyadmin to manage my database while i'm coding in django?
Thank you.

Niloofar24 15 Posting Whiz

Hello.
This is my code:

from bs4 import BeautifulSoup
import urllib2

url = urllib2.urlopen('http://www.website_address.com')
soup = BeautifulSoup(url)
images = soup.find_all('img')

Now how can I get the "src" of img tags?

Niloofar24 15 Posting Whiz

Hi.
I'm creating a web crawler, I want to send the output into a txt file, how can I do it? And I also want to give a path to the script to set the directory. How can I do it now?

Niloofar24 15 Posting Whiz

Hello.
There is a text in my Python script that is in Persian language and the letters are from left to right, but in Persian language letters should be written from right to left.
What should i do now to fix it and print it in UTF-8 format?

Niloofar24 15 Posting Whiz

You are right I'm sorry for the question. Of course I didn't ask it to do an illegal action. I was going to test the security of my frind's server to make sure about it's security as we were trying to work on it's security... but anyway i forgot about DaniWeb ruels so sorry.

Niloofar24 15 Posting Whiz

Why 2 members gave me 2 negative points?! What was the problem of my question?

Niloofar24 15 Posting Whiz

Yes I mean a DDOS attack. Well, I mean a successful attack, just this!

Niloofar24 15 Posting Whiz

Hello everybody.
I'm looking for a good cool and fun DDOS script in python.
Any suggestion?

How can I create a good fun DDOS script using URLLIB?!

Niloofar24 15 Posting Whiz

Would you please help me more clear? I don't know what to do exactly yet.
I don't want to use many font style just less than 8!

Niloofar24 15 Posting Whiz

Well, there is a problem, this is my code for now:

<html>
<head>
<style>
#main-font {
width: 300px;
height: 120px;
background-color: white;
opacity: 0.2;
border-radius: 20px;
box-shadow: 0px 0px 10px black;
margin-left: 470px;
margin-top: -500px;
}

#font {
width: 250px;
height: 100px;
margin-left: 505px;
margin-top: -105px;
position: absolute;
}

#font option{
width: 200px;
}

p {
font-family = $font;
}

@font-face {
font-family: ArchitectsDaughter;
src: url(fonts/ArchitectsDaughter.ttf);
}

@font-face {
font-family: Armata-Regular;
src: url(fonts/Armata-Regular.otf);
}

@font-face {
font-family: DJB-Ms-Rachel;
src: url(fonts/DJB-Ms-Rachel.otf);
}

@font-face {
font-family: EncodeSansNarrow-Thin;
src: url(fonts/EncodeSansNarrow-Thin.ttf);
}
</style>

<script>
$("select#fChange").change(function(){
    var font = $(this ).val();
    $("#uName").attr("style", "font-family: " + font);
});
</script>

</head>
<body>

<div id="main-font"></div>

<div id="font">
Choose your font:<br>
<form method='post'>
<select name="font_styles" id="fChange">
  <option>choose font</option>
  <option value="ArchitectsDaughter.ttf">ArchitectsDaughter.ttf</option>
  <option value="Armata-Regular.otf">Armata-Regular.otf</option>
  <option value="DJB-Ms-Rachel.otf">DJB-Ms-Rachel.otf</option>
  <option value="EncodeSansNarrow-Thin.ttf">EncodeSansNarrow-Thin.ttf</option>
</select>
<input type="submit" name="font_submit">
</form>
<center><p id="uName">niloofar</p></center>
</div>


<?php
if(isset($_POST['font_submit'])) {

$user_choice = $_POST['font_styles'];

if ($user_choice == "ArchitectsDaughter.ttf"){
$font = 'ArchitectsDaughter';
}elseif ($user_choice == "Armata-Regular.otf"){
$font = 'Armata-Regular';
}elseif ($user_choice == "DJB-Ms-Rachel.otf"){
$font = 'DJB-Ms-Rachel';
}elseif ($user_choice == "EncodeSansNarrow-Thin.ttf"){
$font = 'EncodeSansNarrow-Thin';
}
}
?>

</body>
</html>

Now when i choose a font and click the submit button, nothing happens, just the option of the drop-down menu changes to "choose font"!!! Why?!

Niloofar24 15 Posting Whiz

Hello.
Is there any other way for not using the submit button?

<?php

$user_choice = $_POST['font_styles'];

if ($user_choice == "font_style_1"){
    $font = 'firstfont';
}elseif ($user_choice == "font_style_2"){
    $font = 'secondfont';
}elseif ($user_choice == "font_style_3"){
    $font = 'thiredfont';
}elseif ($user_choice == "font_style_4"){
    $font = 'forthfont';
}

?>

<html>
<head>
<style>

h1 {
font-family = $font;
}

</style>
</head>
<body>

    <form method='post'>
    <select name="font_styles">
    <option value="font_style_1">font_style_1</option>
    <option value="font_style_2">font_style_2</option>
    <option value="font_style_3">font_style_3</option>
    <option value="font_style_4">font_style_4</option>
    </select>
    <input type="submit">
    </form>

    <h1>username</h1>

 </body>
 </html>

I want when a user opens the drop-down menu and chooses an option, the font of the <h1> tag changes and the user can see his/her name in that font to see if he/she wants to save changes or choose an other font.
But I dn't want any submit button to be there, I want the font of the <h1> tag changes just by selecting a drop-down option. Is it possible?

Niloofar24 15 Posting Whiz

Hi.
I want to create a drop-down menu for user's location (choosing cities) in the form.
I know how to create it, but as I want a long list of citis, so is there any other way to create it? Or do i have to create each city one by one?!

Niloofar24 15 Posting Whiz

Hi.
There is a textarea in my page. I type a text in the textare and then in the script there is:

    $text = nl2br(htmlentities($_POST['text']));

Now what is the problem?
When i type:

I'm fine.

It will be sent to db and will be printed, in both place as:

I\'m fine.

What is the solution for that?

Niloofar24 15 Posting Whiz

Good.
Any more suggestion?!

Niloofar24 15 Posting Whiz

Thank you @diafol, it works now. And thank you @lorenzoDAlipio for the link.
And thank you all friends.

But I still can't get the css tags from a web page?
Could you help me more witn more clear explanation please?!

Niloofar24 15 Posting Whiz

Hi.
I'm thinking about a new project in php.... any idea of a cool and fun or useful and efficient project?!

Niloofar24 15 Posting Whiz

It dosen't work.

<?php

echo file_get_html('https://www.daniweb.com/');

?>
Niloofar24 15 Posting Whiz

Who knows why file_get_html() doesn't work for me, any idea?

@lorenzoDAlipio, i have downloaded php html DOM parser API zip folder, what should i do know with it? Is there any special file needed to be placed in the localhost? (Sorry i need help for that, I don't know how to use it, thank you.)

Niloofar24 15 Posting Whiz

@TexWiller, file_get_html() didn't work for me because of the html word in it and had to replace it with the word contents to get a result.

and also with:

foreach($html->find('img') as $element)
       echo $element->src . '<br>';

foreach($html->find('a') as $element)
       echo $element->href . '<br>';

there was no result and nothing appeaed on the page. (for www.google.com).

Niloofar24 15 Posting Whiz

Can you give me an example please if it possible?

Niloofar24 15 Posting Whiz

Hi.
With using file_get_contents() I can get all html tags and text of a web page. But is there any way to get that web page's css codes too?

Niloofar24 15 Posting Whiz

Thank you @diafol.

Niloofar24 15 Posting Whiz

I found the solution myself. Thank you.

Niloofar24 15 Posting Whiz

Waht do you mean by the file is probably not mine?!
I typed that and the result:
-rw-r--r-- 1 root root

Niloofar24 15 Posting Whiz

I found an example myself:

    $url = “http://www.howtogeek.com”;

    $str = file_get_contents($url);
Niloofar24 15 Posting Whiz

Hello.
When i open a file in my linux localhost with the command "gedit file.php" and then put a part of code in it, then i can't save the file. the save icon above the gedit is deactivated.
What can i do?

Niloofar24 15 Posting Whiz

Would you give me an example please?
An example that you give a url to the script, and it gets all the html tags and text of that page and echo it on a file. I want the output to have text and html tags together.

Niloofar24 15 Posting Whiz

Yes Thanks friends.

Niloofar24 15 Posting Whiz

Well, like in python.... for example with a web crawler (with BeautifulSop if I'm correct) that we can get all html tags and text of a web page and then save it to a text file.

I want to do the same with php, give the url of a web page and receive it's html tags and contents.

Niloofar24 15 Posting Whiz

Hello.
How can i create a new file in my linux localhost?

Niloofar24 15 Posting Whiz

Hello.
How can i get the html tags and texts of a web page in php?

Niloofar24 15 Posting Whiz

It works. Thank you @joshuajames.delacruz. Thank you @pzuurveen.

Niloofar24 15 Posting Whiz

Hello.
This is a part of my script:

<table id="table-5">
    <thead>
        <th>ID</th>
        <th>URL</th>
        <th>Editor</th>
        <td>More....</td>
    </thead>
    <tbody>

<?php

include('connection.php');
try {
$sql = "SELECT * FROM Data ORDER BY ID DESC";
$result = $conn->query($sql);

foreach($result as $key => $row) {
        echo "<tr>";
        echo "<td>" . $row['ID'] . "</td>";
        echo "<td>" . $row['URL'] . "</td>";
    echo "<td>" . $row['Editor'] . "</td>";
    echo "<td><a id='more' href='http://www.niloofar3D.ir' onClick='return popup(this, 'mypopup')'><button>&raquo;</button></a></td>";
    echo "</tr>";
}

} catch(PDOException $e) {
    echo "Query error:".$sql . "<br>" . $e->getMessage();
}

$conn = null;
?>

    </tbody>



</table>

Line 22 is a button that is popup. But as I have put it here in the php part of the code, it doesn't work now. It acts as clicking a link right now.

But will act as a popup in this way:

<td><a id="more" href="http://www.niloofar3D.ir" onClick="return popup(this, 'mypopup')"><button>&raquo;</button></a></td>

How can i fix it. Because of " and ' this problem has happend.

Niloofar24 15 Posting Whiz

I understood. Thanks friends.

Niloofar24 15 Posting Whiz

Well, I still haven't got what to do exactly. Where should I put CURRENT_TIMESTAMP() in the script? I'm using PDO.
Would you please help me more?

Niloofar24 15 Posting Whiz

Hello everybody.
There is a row in my db table I have set it's type as "TIMESTAMP". How should I fill in?
Should get the current timestamp in php and send it to that row, correct?
So how can I do that?

Niloofar24 15 Posting Whiz

So there is no answer?!

Niloofar24 15 Posting Whiz

Yessssssss:D I found the problem myself finally!
So let's explain it for other member's may have this same problem too.

Look at my code, line 8:

<link rel="stylesheet" type="text/css" href="bootstrap.min.css">

We use href="bootstrap.min.css" when we want to host bootstrap ourself, so we download the file and create a link like that.

But when i downloaded bootstrap.min.js and bootbox.min.js from the "Bootbox.js" website, there were no bootstrap.min.css to download. So the problem was because of the lack of the bootstap.min.css file. So it didn't work well.

Then i replaced that with:

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">

So href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" will create link to CND and the script works well with no problem.

That'a all!

Niloofar24 15 Posting Whiz

@jstfsklh211, i found a problem that i didn't attention to it before.

Without using display: none;, the output was like this:

first picture

And the only problem was appearing the div befor clicking the button by default when the page loads.

But now with using display: none;; the output is like this:

second picture

Now when the page loads, the div is disappeared by default and user have to click the button to appear the div by toggling, and it's ok.

But the problem is that as you see in the second picture, the height of the div is less than before and also the text in the div is broke down. The text was "Welcome guest!" but the only word is able to see is "Welcome".

If i set an amount for div's height and make it more higher, then the word "guest!" will be appeared under the word "Welcome".
Something like this:

Welcome
guest!

Anyway, who can i fix it? What is the problem? Why it happend?

Niloofar24 15 Posting Whiz

You like torturing people, don't you :D?

Oh no! just want to learn everything deeply :D

Thank you for the links.

Niloofar24 15 Posting Whiz

So, i solved it in this way:

     '/Arch/i' => 'Arch Linux',
    '/ubuntu/i' => 'Ubuntu Linux',

So would it be correct?

Niloofar24 15 Posting Whiz

Thank you @Aeonix i undersood. The script can't echo both OS nad it's Distribution yet, i will check to see if i can solve it or have to back here for asking more helps.

And would it be ok if i ask you to explain this for me too!!
preg_match("/^[A-Za-z0-9'?!-\s\\\\]+$/", $field)
If you know it, Thank you.

Niloofar24 15 Posting Whiz

Well would you please explain it for me?

  // what does /ubuntu/i means?
 '/ubuntu/i' => 'Ubuntu',

I mean / and / and i.

Niloofar24 15 Posting Whiz

I mean both OS and the Distribution of that.

Niloofar24 15 Posting Whiz

Yes it works, thank you @jstfsklh211.